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

export default function Index({ title = '房屋档案' }) {
  const navigate = useNavigate();

  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        // search={false}
        request={async (params, sort) =>
          MyProTableProps.request(params, sort, Apis.Asset.AssetHouses.List)
        }
        columns={[
          MyColumns.ID(),
          MyColumns.EnumTag({
            title: '产权性质',
            dataIndex: 'ownership_type',
            valueEnum: AssetHousesOwnershipTypeEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '用途',
            dataIndex: 'usage',
            valueEnum: AssetHousesUsageEnum,
            search: false,
            width: 80,
          }),
          {
            title: '房屋名称',
            dataIndex: 'full_name',
          },
          {
            title: '楼层',
            dataIndex: 'floor',
            render(_, record) {
              return `${record?.floor}层`;
            },
            search: false,
            width: 60,
          },
          {
            title: '建筑面积',
            dataIndex: 'built_area',
            render(_, record) {
              return `${record?.built_area} m²`;
            },
            search: false,
            width: 80,
          },
          {
            title: '套内面积',
            dataIndex: 'inside_area',
            render(_, record) {
              return `${record?.inside_area} m²`;
            },
            search: false,
            width: 80,
          },
          {
            title: '计费面积',
            dataIndex: 'chargeable_area',
            render(_, record) {
              return `${record?.chargeable_area} m²`;
            },
            search: false,
            width: 80,
          },

          MyColumns.EnumTag({
            title: '房屋状态',
            dataIndex: 'status',
            valueEnum: AssetHousesStatusEnum,
            search: false,
          }),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                {item?.house_occupants?.length !== 0 && (
                  <MyButtons.View
                    title="详情"
                    onClick={() => {
                      navigate(`/archive/asset_house/${item.id}`);
                    }}
                  />
                )}
                {!item?.house_occupants?.length && (
                  <Delivery
                    item={item}
                    reload={action?.reload}
                    title="入户登记"
                  />
                )}
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
