import {
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { HouseRegistersStatusEnum, HouseRegistersTypeEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import Audit from './modals/Audit';

export default function Index({ title = '登记审核' }) {
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'examine-house-registers-audit',
    tabLabel: title,
  });
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            { status: 'Pending', ...params },
            sort,
            Apis.Archive.HouseRegisters.List,
          )
        }
        columns={[
          MyColumns.ID(),
          {
            title: '客户信息',
            dataIndex: ['asset_house', 'full_name'],
            search: {
              transform: (value) => {
                return { house_name: value };
              },
            },
          },
          {
            title: '客户信息',
            render(_, record) {
              return (
                record?.customer_info?.map((res: any) => res?.name).join(';') ||
                '-'
              ); // 无数据时显示 -
            },
            search: false,
          },
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'type',
            valueEnum: HouseRegistersTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: HouseRegistersStatusEnum,
          }),
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <Audit item={item} reload={action?.reload} title={title} />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
