// @flow
import React from 'react'
import {ScrollView, Image, StyleSheet} from 'react-native'
import * as Icons from '@hawkrives/react-native-alternate-icons'
import {Section, Cell} from 'react-native-tableview-simple'
import {icons as appIcons} from '../../../images/icon-images'
import * as c from '../components/colors'
import type {TopLevelViewPropsType} from '../types'

const styles = StyleSheet.create({
  icon: {
    width: 16,
    height: 16,
    borderColor: c.black,
    borderRadius: 5,
    borderWidth: StyleSheet.hairlineWidth,
  },
})

type IconTypeEnum = 'default' | 'icon_type_windmill'

type Icon = {
  src: any,
  title: string,
  type: IconTypeEnum,
}

export const icons: Array<Icon> = [
  {
    src: appIcons.oldMain,
    title: 'Old Main',
    type: 'default',
  },
  {
    src: appIcons.windmill,
    title: 'Wind Turbine (Big Ole)',
    type: 'icon_type_windmill',
  },
]

type Props = TopLevelViewPropsType & {}

type State = {
  iconType: ?string,
}

export class IconSettingsView extends React.PureComponent<Props, State> {
  static navigationOptions = {
    title: 'App Icon',
  }

  state = {
    iconType: null,
  }

  componentWillMount() {
    this.getIcon()
  }

  setIcon = async (iconType: string) => {
    if (iconType === 'default') {
      await Icons.reset()
    } else {
      await Icons.setIconName(iconType)
    }

    this.getIcon()
  }

  getIcon = async () => {
    const name = await Icons.getIconName()
    this.setState(() => ({iconType: name}))
  }

  render() {
    return (
      <ScrollView>
        <Section header="CHANGE YOUR APP ICON" separatorInsetLeft={58}>
          {icons.map(icon => (
            <Cell
              accessory={
                this.state.iconType === icon.type ? 'Checkmark' : undefined
              }
              cellStyle="RightDetail"
              disableImageResize={false}
              key={icon.title}
              image={<Image style={styles.icon} source={icon.src} />}
              onPress={() => this.setIcon(icon.type)}
              title={icon.title}
            />
          ))}
        </Section>
      </ScrollView>
    )
  }
}

@@ -1861,39 +1861,8 @@
 se%7D%0A
-              key=%7Bicon.title%7D%0A
     
@@ -1927,16 +1927,47 @@
 rc%7D /%3E%7D%0A
+              key=%7Bicon.title%7D%0A
         

Alphabetize cell props