import { Button, Form, Input, Modal } from 'antd'
import { useState } from 'react'
import { useCopyDataset } from '../query'

export default function CopyButtonModal({ children, data }: { children?: string; data: any }) {
  const [open, setOpen] = useState(false)

  const [form] = Form.useForm()

  const { mutate, isPending } = useCopyDataset()

  const handleOk = () => {
    form.validateFields().then((values) => {
      const params = { id: data.id, force: '1', ...values }
      mutate(params, {
        onSuccess: () => setOpen(false),
      })
    })
  }
  return (
    <>
      <Button color="primary" variant="text" onClick={() => setOpen(true)}>
        {children ? children : '复制'}
      </Button>
      <Modal
        title="复制数据集"
        open={open}
        onOk={handleOk}
        onCancel={() => setOpen(false)}
        confirmLoading={isPending}
        okText="复制"
        destroyOnClose>
        <Form form={form} labelCol={{ span: 5 }} preserve={false}>
          <Form.Item label="数据集名称" name="name">
            <Input placeholder="请输入" />
          </Form.Item>
          <Form.Item label="原始数据集">{data.name}</Form.Item>
          <Form.Item label="数据量">{data.number}</Form.Item>
          <Form.Item label="所属行业">{data.industry_name}</Form.Item>
          <Form.Item label="数据来源">{data.source_name}</Form.Item>
          <Form.Item label="敏感等级">{data.sensitivity_level_name}</Form.Item>
          <Form.Item label="访问权限">{data.access_permissions_name}</Form.Item>
          <Form.Item label="创建人">{data.created_operator_name}</Form.Item>
          <Form.Item label="创建时间">{data.created_time}</Form.Item>
          <Form.Item label="更新时间">{data.updated_time}</Form.Item>
        </Form>
      </Modal>
    </>
  )
}
