// @flow
import * as React from 'react'
import * as Types from '../../constants/types/fs'
import * as Constants from '../../constants/fs'
import {globalStyles, globalColors, globalMargins, platformStyles} from '../../styles'
import {Box, Button, Text} from '../../common-adapters'
import PathItemInfo from '../common/path-item-info'
import PathItemIcon from '../common/path-item-icon'
import memoize from 'lodash/memoize'
import {fileUIName, isMobile} from '../../constants/platform'

type DefaultViewProps = {
  fileUIEnabled: boolean,
  itemStyles: Types.ItemStyles,
  pathItem: Types.PathItem,

  onDownload: () => void,
  onSave: () => void,
  onShare: () => void,
  onOpenAsText: () => void,
  onShowInFileUI: () => void,
}

const DefaultView = (props: DefaultViewProps) => (
  <Box style={stylesContainer}>
    <PathItemIcon spec={props.itemStyles.iconSpec} style={{}} />
    <Text type="BodyBig" style={stylesFilename(props.itemStyles.textColor)}>
      {props.pathItem.name}
    </Text>
    <Text type="BodySmall">{Constants.humanReadableFileSize(props.pathItem.size)}</Text>
    {isMobile && (
      <PathItemInfo
        lastModifiedTimestamp={props.pathItem.lastModifiedTimestamp}
        lastWriter={props.pathItem.lastWriter.username}
        startWithLastModified={true}
      />
    )}
    {props.pathItem.type === 'symlink' && (
      <Text type="BodySmall" style={stylesSymlink}>
        {'This is a symlink' + (props.pathItem.linkTarget ? ` to: ${props.pathItem.linkTarget}.` : '.')}
      </Text>
    )}
    {isMobile && (
      <Text type="BodySmall" style={stylesNoOpenMobile}>
        This document can not be opened on mobile. You can still interact with it using the ••• menu.
      </Text>
    )}
    {// Enable this button for desktop when we have in-app sharing.
    isMobile && (
      <Button
        key="share"
        type="Primary"
        label="Share"
        style={{marginTop: globalMargins.medium}}
        onClick={props.onShare}
      />
    )}
    {props.fileUIEnabled ? (
      <Button
        key="open"
        type="Secondary"
        label={'Show in ' + fileUIName}
        style={{marginTop: globalMargins.small}}
        onClick={props.onShowInFileUI}
      />
    ) : (
      <Button
        key="download"
        type="Secondary"
        label="Download a copy"
        style={{marginTop: globalMargins.small}}
        onClick={props.onDownload}
      />
    )}
    {// We only show this button for files with no extensions, because our
    // mime type list cannot be exaustive. For example it'd be weird to show
    // an Illustrator file as plain text.
    props.pathItem.name.indexOf('.') === -1 &&
      // We don't want show this button for symlinks.
      props.pathItem.type === 'file' && (
        <Button
          key="open-text"
          type="Secondary"
          label="Open as text"
          style={{marginTop: globalMargins.small}}
          onClick={props.onOpenAsText}
        />
      )}
  </Box>
)

const stylesContainer = platformStyles({
  common: {
    ...globalStyles.flexBoxColumn,
    ...globalStyles.flexGrow,
    width: '100%',
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: globalColors.white,
  },
  isMobile: {
    marginTop: 32,
  },
  isElectron: {
    marginTop: globalMargins.medium,
    marginBottom: globalMargins.medium,
  },
})

const stylesFilename = memoize(color => ({
  marginTop: globalMargins.small,
  marginBottom: globalMargins.tiny,
  color: color,
}))

const stylesSymlink = {
  marginTop: globalMargins.medium,
}

const stylesNoOpenMobile = {
  marginTop: globalMargins.medium,
  width: 295,
}

export default DefaultView

@@ -443,16 +443,23 @@
 isMobile
+, isIOS
 %7D from '
@@ -1986,24 +1986,41 @@
     )%7D%0A    %7B
+!isIOS &&%0A      (
 props.fileUI
@@ -2031,16 +2031,18 @@
 led ? (%0A
+  
       %3CB
@@ -2047,32 +2047,34 @@
 %3CButton%0A        
+  
 key=%22open%22%0A     
@@ -2068,16 +2068,18 @@
 =%22open%22%0A
+  
         
@@ -2087,32 +2087,34 @@
 ype=%22Secondary%22%0A
+  
         label=%7B'
@@ -2137,32 +2137,34 @@
 UIName%7D%0A        
+  
 style=%7B%7BmarginTo
@@ -2188,32 +2188,34 @@
 small%7D%7D%0A        
+  
 onClick=%7Bprops.o
@@ -2239,21 +2239,27 @@
     
+  
 /%3E%0A    
+ 
+ 
 ) : (%0A
+  
     
@@ -2272,24 +2272,26 @@
 ton%0A        
+  
 key=%22downloa
@@ -2293,32 +2293,34 @@
 wnload%22%0A        
+ 
+ 
 type=%22Secondary%22
@@ -2312,32 +2312,34 @@
 ype=%22Secondary%22%0A
+  
         label=%22D
@@ -2354,32 +2354,34 @@
 a copy%22%0A        
+  
 style=%7B%7BmarginTo
@@ -2405,32 +2405,34 @@
 small%7D%7D%0A        
+ 
+ 
 onClick=%7Bprops.o
@@ -2440,39 +2440,44 @@
 Download%7D%0A      
+  
 /%3E%0A    
+  )
 )%7D%0A    %7B// We on

remove download button for mobile (#12106)