import React, { useRef } from 'react';
import { createForm } from '@formily/core';
import { createSchemaField } from '@formily/react';
import Modal, { ModalProps } from '@/components/Modal';
// import { fetchTableData } from '@/utils/table';
import { Form, FormItem, Input, NumberPicker } from '@formily/antd';

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

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

const form = createForm({});

const AddNftContractModal = ({ onOk, onCancel, ...rest }: AddNftContractModalPropsType) => {
  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="token_name"
            title="合约名称"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="token_symbol"
            title="合约单位"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="description"
            title="描述"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
        </SchemaField>
      </Form>
    </Modal>
  );
};

export default AddNftContractModal;
