// 添加代币类型弹窗
import React, { useRef } 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 AddCoinTypeModalPropsType extends ModalProps {
  onOk: (val: any) => void;
  onCancel: () => void;
}

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

const form = createForm({});

const AddCoinTypeModal = ({ onOk, onCancel, ...rest }: AddCoinTypeModalPropsType) => {
  const handleOk = async () => {
    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="货币名称"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.Number
            name="usdt_price"
            title="usdt比例"
            required
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
          <SchemaField.Number
            name="eth_price"
            title="eth比例"
            required
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
          <SchemaField.String
            name="tokenName"
            title="代币名称"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="tokenSymbol"
            title="代币单位"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.Number
            name="num"
            title="数量"
            required
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
        </SchemaField>
      </Form>
    </Modal>
  );
};

export default AddCoinTypeModal;
