import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate, useParams } from '@umijs/max';
import { Space } from 'antd';
import Show from './modals/Show';
import Update from './modals/Update';

export default function Index({ title = '合同用章' }) {
  const navigate = useNavigate();

  const { id } = useParams<{ id: string }>();
  return (
    <ProTable<Record<any, any>>
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(
          params,
          sort,
          Apis.Contract.ContractSealLogs.List,
        )
      }
      headerTitle="已用印合同"
      params={{ contracts_id: id }}
      // toolBarRender={(action) => [
      //   <Create
      //     key="Create"
      //     reload={action?.reload}
      //     item={{ contracts_id: id }}
      //     title={title}
      //   />,
      // ]}
      columns={[
        // MyColumns.ID({
        //   search: false,
        // }),

        {
          title: '合同名称',
          dataIndex: ['contract', 'name'],
        },
        {
          title: '合同编号',
          dataIndex: ['contract', 'code'],
          render: (_, item: any) => {
            return (
              <a
                onClick={() => {
                  navigate(`/contract/contracts/show/${item.contracts_id}`);
                }}
              >
                {item?.contract?.code}
              </a>
            );
          },
        },
        {
          title: '合同编号',
          dataIndex: 'code',
          hidden: true,
        },
        // {
        //   title: '合同ID',
        //   dataIndex: 'contracts_id',
        // },
        {
          title: '印章',
          search: false,
          render: (_, item: any) => (
            <Space>
              {item?.seal_info?.map((res: any) => {
                return res?.company_name;
              })}
            </Space>
          ),
        },
        {
          title: '申请用印人',
          dataIndex: ['company_employee', 'name'],
          search: false,
        },

        {
          title: '用印合同',
          dataIndex: 'number_contract_copies',
          search: false,
        },
        // MyColumns.Boolean({
        //   dataIndex: 'is_external_seal_usage',
        //   title: '是否外出用印',
        //   search: false,
        // }),
        {
          title: '操作印章人',
          dataIndex: ['operator_employee', 'name'],
          search: false,
        },
        MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>
              <Show item={item} />
              <Update item={item} reload={action?.reload} title={title} />
            </Space>
          ),
        }),
      ]}
    />
  );
}
