import {
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  MyTableActions,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { HouseRegistersStatusEnum, HouseRegistersTypeEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from 'umi';
import Audit from './modals/Audit';
import Show from './modals/Show';

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,
                HouseRegistersTypeEnum.Transfer.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, __, action) => (
              <MyTableActions
                actions={{
                  audit: (
                    <Audit item={item} reload={action?.reload} title={title} />
                  ),
                  view: <Show item={item} title={title} />,
                }}
              />
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
