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

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

const form = createForm({});

const AddNftModal = ({ onOk, onCancel, ...rest }: AddNftModalPropsType) => {
  const handleOk = () => {
    form.submit(() => {
      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.Number
            name="token_id"
            title="ID"
            x-decorator="FormItem"
            x-component="NumberPicker"
          />
          <SchemaField.String
            name="toAddress"
            title="所有者地址"
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="name"
            title="名称"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="image"
            title="图片"
            required
            x-decorator="FormItem"
            x-component="Input"
          />
          <SchemaField.String
            name="avatar"
            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 AddNftModal;
