/**
 * 新充电流程：停止充电模块
 * @邠心vbe on 2023/06/20
 */
import React, { useEffect, useState } from 'react';
import { View, Text, Image, StyleSheet } from 'react-native';
import { PaymentList } from '../chargeV2/Payment';

export default StepStop = ({
  currentPayment,
  curerntPerUse
}) => {
  const [loadingEmps, setEmps] = useState("");

  useEffect(() => {
    changeEmps();
  }, []);

  useEffect(() => {
    setTimeout(() => {
      changeEmps();
    }, 500);
  }, [loadingEmps]);

  const changeEmps = () => {
    let emp = loadingEmps;
    if (loadingEmps.length == 3) {
      emp = "";
    } else {
      emp += ".";
    }
    setEmps(emp);
  }

  return (
    <View style={styles.container}>
      <View style={styles.content}>
        <Image
          style={styles.stepImage}
          resizeMode="contain"
          source={require('../../images/site/charging-status-ready.png')}
        />
        <View style={ui.flexcc}>
          <Text style={styles.stepTitle}>{$t('charging.stepStoppingCharge')}</Text>
          <Text style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</Text>
        </View>
        <Text style={styles.stepDesc}>{$t('charging.stepStoppingChargeDesc')}</Text>
      </View>

      <View style={styles.bottomView}>
      <Text style={styles.label}>{$t('charging.paymentMethod')}</Text>
        <PaymentList
          payType={currentPayment}
          payPerUse={curerntPerUse}
        />
        <View style={{height: 56}}/>
      </View>
    </View>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 16
  },
  content: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
  },
  stepImage: {
    width: $vw(70),
    height: $vw(16),
    margin: 16
  },
  stepTitle: {
    fontSize: 24,
    fontWeight: 'bold',
    color: colorAccent
  },
  stepDesc: {
    color: textPrimary,
    fontSize: 16,
    textAlign: 'center',
    ...$padding(0, 32, 48)
  },
  label: {
    color: '#000',
    fontSize: 14,
    fontWeight: 'bold',
    paddingTop: 16,
    paddingBottom: 8
  },
  bottomView: {
    paddingBottom: 16
  },
  buttonView: {
    marginTop: 8
  }
})