// 修改弹窗
import React, { useRef, useEffect } from 'react';
import { createForm } from '@formily/core';
import { createSchemaField } from '@formily/react';
import Modal, { ModalProps } from '@/components/Modal';
import { Form, FormItem, Input, Select } from '@formily/antd';

interface EditAddressModalPropsType extends ModalProps {
  editModalData: any;
  onOk: (val: any) => void;
  onCancel: () => void;
}

const SchemaField = createSchemaField({
  components: {
    FormItem,
    Input,
    Select,
  },
});

const form = createForm({});

const EditAddressModal = ({
  onOk,
  onCancel,
  editModalData,
  ...rest
}: EditAddressModalPropsType) => {
  useEffect(() => {
    form.setInitialValues(editModalData);
  });

  const handleOk = () => {
    const formState = form.getFormState();
    onOk(formState.values);
  };

  const handleCancel = () => {
    onCancel();
  };

  return (
    <Modal title="修改收款地址" onOk={handleOk} onCancel={handleCancel} width={800} {...rest}>
      <Form form={form} labelCol={4} wrapperCol={18}>
        <SchemaField>
          <SchemaField.String
            name="address"
            title="旧收款地址"
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="bc_type"
            title="游戏币类型"
            required
            x-decorator="FormItem"
            x-component="Select"
          />
          <SchemaField.String
            name="new_address"
            title="新收款地址"
            x-decorator="FormItem"
            x-component="Input"
          />
        </SchemaField>
      </Form>
    </Modal>
  );
};

export default EditAddressModal;
