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 { useNavigate } from 'umi';
import Audit from './modals/Audit';

export default function Index({ title = '登记审核' }) {
  const navigate = useNavigate();
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'examine-house-registers-audit',
    tabLabel: title,
  });
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Archive.HouseRegisters.List,
          )
        }
        columns={[
          MyColumns.ID(),
          {
            title: '房屋名称',
            dataIndex: ['asset_house', 'full_name'],
            search: {
              transform: (value) => {
                return { house_name: value };
              },
            },
            render: (text, record) => (
              <a onClick={() => navigate(`/archive/show/${record.model_id}`)}>
                {text}
              </a>
            ),
          },
          {
            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}>
                {item?.status === HouseRegistersStatusEnum.Pending.value && (
                  <Audit item={item} reload={action?.reload} title={title} />
                )}
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
