// 修改弹窗
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, NumberPicker } from '@formily/antd';

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

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

const form = createForm({});

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

  const handleOk = () => {
    form.submit(async () => {
      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="name"
            title="游戏币名称"
            x-disabled
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.Number
            name="usdt_price"
            title="usdt比例"
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
          <SchemaField.Number
            name="eth_price"
            title="eth比例"
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
        </SchemaField>
      </Form>
    </Modal>
  );
};

export default EditCoinTypeModal;
