/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  TouchableOpacity,
} from 'react-native';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { push, tab } from '../../BasicNavigator/actions';
import themeType from '../../theme';
import themeAction from '../../theme/action';
import NavigationBar from '../../components/NavigationBar';
import BackButton from '../../components/BackButton';
import Button from '../../components/ThemeButton';
import decorator from '../../utils/decorator';

type Props = {};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    margin: 5,
  },
});


class ThemePage extends Component<Props> {

  componentDidMount() : void {
    console.log('ThemePage_componentDidMount');
  }

  render() {
    const { theme, setCurrentTheme } = this.props;

    return (
      <View style={styles.container}>
        <NavigationBar
          left={<BackButton />}
          title="设置主题"
        />
        <Button
          containerStyle={{ height: 40, margin: 10 }}
          onPress={() => {
            setCurrentTheme(themeType.blackTheme);//Object.assign
          }}
          title="切换黑色主题"
        />
        <Button
          containerStyle={{ height: 40, margin: 10 }}
          onPress={() => {
            setCurrentTheme(themeType.defaultTheme);//Object.assign
          }}
          title="切换蓝色主题"
        />
        <Button
          containerStyle={{ height: 40, margin: 10 }}
          onPress={() => {
            setCurrentTheme(themeType.redTheme);//Object.assign
          }}
          title="切换红色主题"
        />
      </View>
    );
  }
}

function propsMapping(props) {
  const { nav, theme } = props;
  return {
    nav,
    theme,
  };
}

function actionMapping(dispatch) {
  return {
    push: compose(dispatch, push),
    tab: compose(dispatch, tab),
    setCurrentTheme: compose(dispatch, themeAction.setCurrentTheme),
  };
}
export default connect(propsMapping, actionMapping)(ThemePage);
