import { MyColumns, MyPageContainer, MyProTableProps } 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();

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="examine-house-registers-audit"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        headerTitle="登记审核"
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              type: [
                HouseRegistersTypeEnum.AddOwner.value,
                HouseRegistersTypeEnum.RemoveOwner.value,
                HouseRegistersTypeEnum.AddOccupant.value,
                HouseRegistersTypeEnum.RemoveOccupant.value,
                HouseRegistersTypeEnum.MoveOut.value,
                HouseRegistersTypeEnum.MoveIn.value,
                HouseRegistersTypeEnum.UpdateInfo.value,
                HouseRegistersTypeEnum.UpdatePhone.value,
              ],
            },
            sort,
            Apis.Archive.HouseRegisters.List,
          )
        }
        columns={[
          MyColumns.ID({ search: false }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: HouseRegistersStatusEnum,
          }),
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'type',
            valueEnum: HouseRegistersTypeEnum,
            search: false,
          }),
          {
            title: '房屋名称',
            dataIndex: ['asset_house', 'full_name'],
            search: {
              transform: (value) => {
                return { house_name: value };
              },
            },
            render: (text, record) => (
              <a
                onClick={() =>
                  navigate(`/customer/archive/show/${record.model_id}`)
                }
              >
                {text}
              </a>
            ),
          },
          {
            title: '客户信息',
            render(_, record) {
              return (
                record?.customer_info?.map((res: any) => res?.name).join(';') ||
                '-'
              ); // 无数据时显示 -
            },
            search: {
              transform: (value) => {
                return { customer_name: value };
              },
            },
          },

          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>
  );
}
