import { MyBetaModalFormProps, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  ContractArchivesConfidentialityLevelEnum,
  ContractArchivesPeriodTypeEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';

import Show from '../../../contract_archives/modals/Show';

export default function Index(props: MyBetaModalFormProps) {
  const navigate = useNavigate();
  return (
    <ProTable
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(
          { ...params, contracts_id: props?.item?.id },
          sort,
          Apis.Contract.ContractArchives.List,
        )
      }
      headerTitle="归档记录"
      search={false}
      // toolBarRender={(action) => [
      //   <Archives
      //     key="Create"
      //     reload={action?.reload}
      //     item={{
      //       id: props?.item?.id,
      //       size: 'middle',
      //       btnType: 'primary',
      //       code: props?.item?.code,
      //       name: props?.item?.name,
      //     }}
      //     title="归档"
      //   />,
      // ]}
      columns={[
        MyColumns.ID({
          search: false,
        }),
        {
          title: '归档编号',
          dataIndex: 'code',
          render: (_, item: any) => (
            <a
              onClick={() => {
                navigate(
                  `/contract/contract_archives/show/${item.contracts_id}`,
                );
              }}
            >
              {item?.code}
            </a>
          ),
        },
        {
          title: '归档名称',
          dataIndex: 'name',
        },
        MyColumns.EnumTag({
          title: '保密等级',
          dataIndex: 'confidentiality_level',
          valueEnum: ContractArchivesConfidentialityLevelEnum,
          search: false,
        }),
        MyColumns.EnumTag({
          title: '期限类型',
          dataIndex: 'period_type',
          valueEnum: ContractArchivesPeriodTypeEnum,
          search: false,
        }),
        {
          title: '保管年限',
          dataIndex: 'storage_years',
          valueType: 'digit',
          search: false,
        },
        // {
        //   title: '案卷编号',
        //   dataIndex: 'file_number',
        // },
        {
          title: '文件盒编号',
          dataIndex: 'box_number',
        },
        {
          title: '文件柜编号',
          dataIndex: 'cabinet_number',
        },
        {
          title: '归档年份',
          dataIndex: 'archive_year',
          valueType: 'dateYear',
          search: false,
        },
        {
          title: '归档日期',
          dataIndex: 'archive_date',
          valueType: 'date',
          search: false,
        },
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={`item_${index}`}>
              <Show item={item} />
              {/* <Update item={item} reload={action?.reload} title="编辑" />
              <MyButtons.Delete
                onConfirm={() =>
                  Apis.Contract.ContractArchives.Delete({ id: item.id }).then(
                    () => action?.reload(),
                  )
                }
              /> */}
            </Space>
          ),
        }),
      ]}
    />
  );
}
