import React from 'react'
import styled from 'styled-components'
import Card, { CardActions, CardContent, CardMedia } from 'material-ui/Card';
import { compose } from 'recompose'


type SubmissionPreviewProps = {
    submission: object
}

const enhance = compose()

const Image = styled(CardMedia) `
height: 300px;
`

export default (props: SubmissionPreviewProps) => {
    let { submission } = props
    console.log(submission.thumbnail, submission)
    let preview
    if (submission.preview && submission.preview.images) {
        let resolutions: object[] = submission.preview.images[0].resolutions
        let heightMoreThan200 = resolutions.filter(r => r.height > 200)
        preview = heightMoreThan200[0] && heightMoreThan200[0].url
    }
    let previewType, gifUrl
    if (submission.url.endsWith('.gif') || submission.url.endsWith('.gifv')) {
        previewType = 'gif'
        gifUrl = submission.url
        if (gifUrl.indexOf('imgur') > 0 && gifUrl.endsWith('.gifv')) {
            gifUrl = gifUrl.substring(0, gifUrl.length - 1)
        }
    } else {
        previewType = 'image'
    }
    if (!preview) {
        return null
    }
    return (
        <div>
            <Image
                onClick={props.handlePreviewClick}
                image={preview}
                title="submission.title"
            />
        </div>
    )
}
@@ -152,16 +152,35 @@
  compose
+, withPropsOnChange
  %7D from 
@@ -251,115 +251,110 @@
 ject
-%0A%7D%0A%0Aconst enhance = compose()%0A%0Aconst Image = styled(CardMedia) %60%0Aheight: 300px;%0A%60%0A%0Aexport default (props: S
+,%0A    preview?: string,%0A    previewType?: string%0A%7D%0A%0Aconst enhance = compose(%0A    withPropsOnChange(%5B's
 ubmi
@@ -362,21 +362,17 @@
 sion
-PreviewP
+'%5D, p
 rops
-)
  =%3E 
@@ -373,24 +373,28 @@
 ps =%3E %7B%0A    
+ 
+   
 let %7B submis
@@ -416,54 +416,8 @@
     
-console.log(submission.thumbnail, submission)%0A
     
@@ -428,24 +428,28 @@
 preview%0A    
+ 
+   
 if (submissi
@@ -487,24 +487,28 @@
 w.images) %7B%0A
+    
         let 
@@ -576,24 +576,28 @@
 ons%0A        
+ 
+   
 let heightMo
@@ -652,24 +652,28 @@
 00)%0A        
+    
 preview = he
@@ -719,26 +719,34 @@
 %5B0%5D.url%0A    
+ 
-%7D%0A
+   %7D%0A    
     let prev
@@ -756,17 +756,28 @@
 Type
-,
+%0A        let
  gifUrl%0A
     
@@ -772,16 +772,20 @@
  gifUrl%0A
+    
     if (
@@ -855,32 +855,36 @@
 fv')) %7B%0A        
+    
 previewType = 'g
@@ -887,16 +887,20 @@
 = 'gif'%0A
+    
         
@@ -927,24 +927,28 @@
 url%0A        
+    
 if (gifUrl.i
@@ -1002,32 +1002,36 @@
 ) %7B%0A            
+    
 gifUrl = gifUrl.
@@ -1066,26 +1066,34 @@
  1)%0A        
+ 
-%7D%0A
+   %7D%0A    
     %7D else %7B
@@ -1093,32 +1093,36 @@
  else %7B%0A        
+ 
+   
 previewType = 'i
@@ -1127,22 +1127,263 @@
 'image'%0A
+    
     %7D%0A
+        return %7B%0A            preview,%0A            previewType,%0A        %7D%0A    %7D),%0A)%0A%0Aconst Image = styled(CardMedia) %60%0Aheight: 300px;%0A%60%0A%0Aexport default enhance((props: SubmissionPreviewProps) =%3E %7B%0A    let %7B preview, previewType %7D = props%0A
     if (
@@ -1391,17 +1391,16 @@
 preview)
- 
 %7B%0A      
@@ -1626,8 +1626,9 @@
 %0A    )%0A%7D
+)

refactor submission preview