import {
  MyButtons,
  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 '@umijs/max';
import RegistersShow from '../archive/table/modals/RegistersShow';

export default function Index({ title = '变更记录' }) {
  const navigate = useNavigate();

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="registers-list"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        headerTitle="变更记录"
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Archive.HouseRegisters.List,
          )
        }
        // toolBarRender={(action) => [
        //   <MyImportModal
        //     key="ImportHouse"
        //     title="批量导入"
        //     type="default"
        //     size="middle"
        //     templateApi={Apis.Archive.HouseOccupants.DownloadTemplate}
        //     importApi={Apis.Archive.HouseOccupants.Import}
        //     reload={action?.reload}
        //   />,
        // ]}
        columns={[
          MyColumns.ID({
            search: false,
          }),
          {
            title: '项目名称',
            dataIndex: ['asset_project', 'name'],
            search: {
              transform: (value) => {
                return { project_name: value };
              },
            },
          },
          {
            title: '房屋名称',
            dataIndex: ['asset_house', 'full_name'],
            ellipsis: true,
            search: false,
            render: (_, item: any, index, action) => (
              <MyButtons.View
                title={item?.asset_house?.full_name}
                type="link"
                onClick={() => {
                  navigate(`/customer/archive/show/${item?.asset_house?.id}`);
                }}
              />
            ),
          },
          {
            title: '客户信息',
            render(_, record) {
              return (
                record?.customer_info?.map((res: any) => res?.name).join(';') ||
                '-'
              ); // 无数据时显示 -
            },
            search: false,
          },
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'type',
            valueEnum: HouseRegistersTypeEnum,
            fieldProps: {
              mode: 'multiple',
            },
          }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: HouseRegistersStatusEnum,
          }),
          {
            title: '登记时间',
            dataIndex: 'created_at',
            valueType: 'dateTime',
            search: false,
          },
          {
            title: '更新时间',
            dataIndex: 'updated_at',
            valueType: 'dateTime',
            search: false,
          },
          MyColumns.Option({
            render: (_, item: any, __, action) => (
              <MyTableActions
                actions={{
                  view: (
                    <RegistersShow
                      item={item}
                      reload={action?.reload}
                      title="查看详情"
                    />
                  ),
                }}
              />
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
