import {
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  AssetHousesOrientationEnum,
  AssetHousesOwnershipTypeEnum,
  AssetHousesStatusEnum,
  AssetHousesUsageEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';
import HousesShow from '../asset/components/modals/HousesShow';
import HousesUpdate from '../asset/components/modals/HousesUpdate';

export default function Index({ title = '房屋列表' }) {
  const navigate = useNavigate();
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'asset-houses',
    tabLabel: title,
  });
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(params, sort, Apis.Asset.AssetHouses.List)
        }
        columns={[
          MyColumns.ID(),
          {
            title: '房屋名称',
            dataIndex: 'full_name',
            ellipsis: true,
          },

          MyColumns.EnumTag({
            title: '用途',
            dataIndex: 'usage',
            valueEnum: AssetHousesUsageEnum,
          }),
          {
            title: '楼层',
            dataIndex: 'floor',
            render(_, record) {
              return `${record?.floor}层`;
            },
            search: false,
          },

          {
            title: '建筑面积',
            dataIndex: 'built_area',
            render(_, record) {
              return `${record?.built_area || ''} m²`;
            },
            search: false,
          },
          {
            title: '套内面积',
            dataIndex: 'inside_area',
            render(_, record) {
              return `${record?.inside_area || ''} m²`;
            },
            search: false,
          },
          {
            title: '计费面积',
            dataIndex: 'chargeable_area',
            render(_, record) {
              return `${record?.chargeable_area || ''} m²`;
            },
            search: false,
          },
          {
            title: '户型',
            render(_, record) {
              return `${record?.room || ''}室${record?.hall || ''}厅${
                record?.bathroom || ''
              }卫${record?.kitchen || ''}厨${record?.balcony || ''}阳台`;
            },
            search: false,
          },
          MyColumns.EnumTag({
            title: '朝向',
            dataIndex: 'orientation',
            valueEnum: AssetHousesOrientationEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '房屋状态',
            dataIndex: 'status',
            valueEnum: AssetHousesStatusEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '产权性质',
            dataIndex: 'ownership_type',
            valueEnum: AssetHousesOwnershipTypeEnum,
            search: false,
          }),

          {
            title: '产权年限',
            dataIndex: 'ownership_term',
            render(_, record) {
              return `${record?.ownership_term || '-'} 年`;
            },
            search: false,
          },
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <HousesShow item={item} reload={action?.reload} />
                <HousesUpdate
                  item={item}
                  reload={action?.reload}
                  title="编辑"
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
