import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';

export default function Index({ title = '转移记录' }) {
  const navigate = useNavigate();

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="archives_transfers"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Contract.ContractArchiveTransfers.List,
          )
        }
        headerTitle="转移记录"
        toolBarRender={() => [
          <MyButtons.Default
            key="back"
            title="返回未归档"
            type="primary"
            size="middle"
            onClick={() => {
              navigate('/contract/contract_archives');
            }}
          />,
        ]}
        columns={[
          MyColumns.ID({ search: false }),
          {
            title: '合同ID',
            dataIndex: 'contracts_id',
            hidden: true,
          },
          {
            title: '原保管人',
            dataIndex: 'old_keeper_name',
            hidden: true,
          },
          {
            title: '新保管人',
            dataIndex: 'new_keeper_name',
            hidden: true,
          },
          {
            title: '原保管人',
            search: false,
            render: (_, item: any) => {
              return `${item?.old_keeper_name}：${item?.old_keeper_phone}`;
            },
          },
          {
            title: '新保管人',
            search: false,
            render: (_, item: any) => {
              return `${item?.new_keeper_name}：${item?.new_keeper_phone}`;
            },
          },
          {
            title: '新存放位置',
            search: false,
            render: (_, res: any) => {
              return `${res?.contract_archive?.province || ''}${
                res?.contract_archive?.city || ''
              }${res?.contract_archive?.area}${
                res?.contract_archive?.street || ''
              }${res?.contract_archive?.address || ''}`;
            },
          },
          {
            title: '文件盒编号',
            dataIndex: ['contract_archive', 'box_number'],
            search: false,
          },
          {
            title: '文件柜编号',
            dataIndex: ['contract_archive', 'cabinet_number'],
            search: false,
          },
          MyColumns.CreatedAt(),
        ]}
      />
    </MyPageContainer>
  );
}
