import { lazy } from 'react'
import { Card, Input, Select } from 'antd'
import AppList, { AppListProps } from '@/components/AppList'
import { useMapStore } from '@/stores/map'
import { getDatasetList } from '../api'

const CopyButtonModal = lazy(() => import('../components/CopyButtonModal'))
const ViewDataButtonModal = lazy(() => import('@/components/data/ViewDataButtonModal'))

export default function DataWriteCopy() {
  const getMapValuesByKey = useMapStore((state) => state.getMapValuesByKey)
  const industryList = getMapValuesByKey('bi_data_industry')

  const listOptions: AppListProps = {
    queryKey: ['dataWriteCopy'],
    fetchApi: async (params) => {
      const { data } = await getDatasetList({ ...params, access_permissions: '1' })
      return { ...data }
    },
    filters: [
      {
        name: 'industry',
        element: <Select placeholder="请选择所属行业" options={industryList} />,
      },
      {
        name: 'name',
        element: <Input placeholder="请输入数据集名称" />,
      },
    ],
    columns: [
      {
        title: '序号',
        key: 'index',
        render(_value, _record, index) {
          return index + 1
        },
        width: 62,
        align: 'center',
      },
      { title: '数据集名称', dataIndex: 'name', align: 'center' },
      { title: '数据量', dataIndex: 'number', align: 'center' },
      { title: '所属行业', dataIndex: 'industry_name', align: 'center' },
      { title: '数据来源', dataIndex: 'source_name', align: 'center' },
      { title: '敏感等级', dataIndex: 'sensitivity_level_name', align: 'center' },
      { title: '访问权限', dataIndex: 'access_permissions_name', align: 'center' },
      { title: '说明', dataIndex: 'describe', align: 'center' },
      { title: '创建人', dataIndex: 'created_operator_name', align: 'center' },
      { title: '创建时间', dataIndex: 'created_time', align: 'center' },
      { title: '更新时间', dataIndex: 'updated_time', align: 'center' },
      {
        title: '操作',
        key: 'x',
        width: 160,
        align: 'center',
        render(_value, record) {
          return (
            <>
              <ViewDataButtonModal data={record}></ViewDataButtonModal>
              <CopyButtonModal data={record}></CopyButtonModal>
            </>
          )
        },
      },
    ],
  }
  return (
    <Card className="app-card" title="数据复制">
      <AppList bordered {...listOptions}></AppList>
    </Card>
  )
}
