import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';

export default function Index({ title = '房客关系' }) {
  const navigate = useNavigate();
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'archive-asset-houses',
    tabLabel: title,
  });
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Archive.HouseOccupants.CustomerList,
          )
        }
        columns={[
          MyColumns.ID(),
          {
            title: '客户名称',
            dataIndex: 'name',
            search: {
              transform: (value) => {
                return { name: value };
              },
            },
          },
          {
            title: '客户电话',
            dataIndex: 'phone',
          },
          MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.View
                  title="查看"
                  onClick={() => {
                    navigate(`/customer/show/${item.id}`);
                  }}
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
