import React, {useState, useEffect} from 'react';

import MethodPayView from './MethodPayView';
import {getListWidthDraw} from '../../apis/Functions/Widthdraw';
import {useNavigation} from '@react-navigation/native';

const MethodPay = (props) => {
  const [data, setData] = useState([]);
  const [isRefresh, setRefresh] = useState(true);

  const navigation = useNavigation();

  useEffect(() => {
    const unsubscribe = navigation.addListener('focus', () => {
      getData();
    });

    return unsubscribe;
  }, [navigation]);

  const getData = async () => {
    const res = await getListWidthDraw({
      platform: Platform.OS,
    });
    if (res.data.code == 200 && res.data.data) {
      setData(res.data.data);
    } else {
      alert('Không lấy được danh sách phương thức thanh toán!');
    }
  };

  return <MethodPayView listMethod={data} />;
};

export default MethodPay;
