import { MyBetaModalFormProps, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import UseSeal from '@/pages/contract/contract_seal_logs/modals/UseSeal';
import { ProTable } from '@ant-design/pro-components';
import { useParams } from '@umijs/max';
import { Space } from 'antd';

export default function Index(props: MyBetaModalFormProps) {
  const { id } = useParams<{ id: string }>();
  return (
    <ProTable<Record<any, any>>
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(
          { ...params, contracts_id: props?.item?.id },
          sort,
          Apis.Contract.ContractSealLogs.List,
        )
      }
      headerTitle="用印列表"
      params={{ contracts_id: id }}
      toolBarRender={(action) => [
        <UseSeal
          item={{ ...props?.item, size: 'middle' }}
          key="create_use_seal"
          reload={action?.reload}
          title="申请用印"
        />,
      ]}
      columns={[
        MyColumns.ID({
          search: false,
        }),
        {
          title: '合同名称',
          dataIndex: ['contract', 'name'],
        },
        {
          title: '合同编号',
          dataIndex: ['contract', 'code'],
        },
        {
          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(),
      ]}
    />
  );
}
