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

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  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';


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


class ThemePage extends Component<Props> {

  render() {
    const { theme, setCurrentTheme } = this.props
    return (
      <View style={styles.container}>
        <Text style={styles.instructions}>ThemeDemo</Text>
        <TouchableOpacity onPress={() => {
          setCurrentTheme(themeType.blackTheme);//Object.assign
        }}
        >
          <Text style={styles.instructions, { color: theme.themeColor }}>启动黑色主题</Text>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => {
          setCurrentTheme(themeType.defaultTheme);//Object.assign
        }}
        >
          <Text style={styles.instructions, { color: theme.themeColor }}>启动蓝色主题</Text>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => {
          setCurrentTheme(themeType.redTheme);//Object.assign
        }}
        >
          <Text style={styles.instructions, { color: theme.themeColor }}>启动红色主题</Text>
        </TouchableOpacity>
      </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);
