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 { useNavigate } from '@umijs/max';
import { Space } from 'antd';
import RegistersShow from '../archive/table/modals/RegistersShow';

export default function Index({ title = '客户列表' }) {
  const navigate = useNavigate();

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="customer-list"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        headerTitle={title}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Archive.HouseRegisters.List,
          )
        }
        columns={[
          MyColumns.ID({
            search: false,
          }),
          {
            title: '房屋信息',
            dataIndex: ['asset_house', 'full_name'],
            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: false,
          },
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'type',
            valueEnum: HouseRegistersTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: HouseRegistersStatusEnum,
          }),
          {
            title: '更新时间',
            dataIndex: 'updated_at',
            valueType: 'dateTime',
            search: false,
          },
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <RegistersShow item={item} title="查看详情" />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
