import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  StyleSheet,
  Image,
  FlatList,
} from 'react-native';
import FastImage from 'react-native-fast-image';
import Icon from 'react-native-vector-icons/FontAwesome5';
import {colors} from '../../assets/styles/colors-theme';
import {Fonts} from '../../assets/styles/fonts-theme';
import history from '../../common/history';
import LoadingView from '../../common/loading';
import moment from 'moment';
import NaviBar from '../../components/navi-bar';
import {scale, verticalScale, moderateScale} from 'react-native-size-matters';
import Migrations from '../../services/realm/Mirgrations';
import {inject, observer} from 'mobx-react';
import {observable} from 'mobx';
import {width, height} from '../../common/screen';
@inject('appStore')
@observer
export default class HistoryList extends Component {
  constructor(props) {
    super(props);
    this.store = props.appStore;
  }

  payment(value) {
    if (value === 'Pending Payment') {
      return (
        <TouchableOpacity>
          <Text style={styles.textView}>
            {'Payment: '}
            <Text
              style={{
                fontFamily: Fonts.ubuntu,
                color: colors.mainColor,
                marginTop: 3,
              }}>
              {value}
            </Text>
          </Text>
        </TouchableOpacity>
      );
    } else {
      return <Text style={styles.textView}>{'Payment: ' + value}</Text>;
    }
  }

  stateChangeLangHandler(value) {
    switch (value) {
      case 'Processing':
        return this.store.text.process;
        break;
      case 'Completed':
        return this.store.text.closeFile;
        break;
      case 'Pending Payment':
        return this.store.text.pendingPayment;
        break;
      default:
        return value;
        break;
    }
  }

  dateHandler(date) {
    return moment(date).format('L');
  }

  render() {
    return (
      <TouchableOpacity
        style={{
          marginTop: 10,
          marginBottom: 10,
          marginLeft: 10,
          marginRight: 10,
        }}
        onPress={this.props.onPress && this.props.onPress}>
        <View
          style={{
            flexDirection: 'row',
            justifyContent: 'space-between',
            alignItems: 'center',
          }}>
          <View>
            <Text style={styles.textView}>
              {this.store.text.id + ': ' + this.props.items.id}
            </Text>
            <Text style={styles.textView}>
              {this.store.text.date +
                ': ' +
                this.dateHandler(this.props.items.createDate)}
            </Text>
            <Text style={styles.textView}>
              {this.store.text.apartment +
                ': ' +
                this.props.items.apartment.name}
            </Text>
            <Text style={styles.textView}>
              {this.store.text.status + ': '}
              <Text style={[styles.textView, {color: colors.mainColor}]}>
                {this.stateChangeLangHandler(this.props.items.status)}
              </Text>
            </Text>
            <Text style={styles.textView}>
              {this.store.text.problems + ': ' + this.props.items.description}
            </Text>

            {/* {this.payment(this.props.items.payment)} */}
          </View>
          <Icon color={colors.textColor} name={'angle-right'} size={30} />
        </View>
        <View
          style={{
            height: 1,
            width: width - 20,
            backgroundColor: colors.textColor,
            marginTop: 15,
          }}
        />
      </TouchableOpacity>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  textView: {
    marginTop: 3,
    fontFamily: Fonts.ubuntu,
    color: colors.textColor,
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  button: {
    borderWidth: 1,
    borderColor: '#000000',
    margin: 5,
    padding: 5,
    width: '70%',
    backgroundColor: '#DDDDDD',
    borderRadius: 5,
  },
  textField: {
    borderWidth: 1,
    borderColor: '#AAAAAA',
    margin: 5,
    padding: 5,
    width: '70%',
  },
  spacer: {
    height: 10,
  },
  title: {
    fontWeight: 'bold',
    fontSize: 20,
    textAlign: 'center',
  },
});
