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 = () => {
    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="contract_name"
            title="名称"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.Number
            name="contract_address"
            title="合约"
            required
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
          <SchemaField.Number
            name="description"
            title=""
            required
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
        </SchemaField>
      </Form>
    </Modal>
  );
};

export default AddNftContractModal;
