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 TransferNFTModelPropsType extends ModalProps {
  onOk: (val: any) => void;
  onCancel: () => void;
}

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

const form = createForm({});

const TransferNFTModel = ({ onOk, onCancel, ...rest }: TransferNFTModelPropsType) => {
  const handleOk = async () => {
    form.submit(async () => {
      const formState = form.getFormState();
      onOk(formState.values);
    });
  };
  const handleCancel = () => {
    onCancel();
  };

  return (
    <Modal title="转账NFT" onOk={handleOk} onCancel={handleCancel} width={800} {...rest}>
      <Form form={form} labelCol={4} wrapperCol={18}>
        <SchemaField>
          <SchemaField.String
            name="token_id"
            title="ID"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="toAddress"
            title="发送地址"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
        </SchemaField>
      </Form>
    </Modal>
  );
};

export default TransferNFTModel;
