import { MyBetaModalFormProps, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  AssetCarPortsPropertyTypeEnum,
  AssetCarPortsStatusEnum,
  AssetCarPortsTypeEnum,
} from '@/gen/Enums';
import SpaceShow from '@/pages/asset/parking_space/modals/SpaceShow';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';

export default function Index(props: MyBetaModalFormProps) {
  const { item } = props;
  if (!item) {
    return null;
  }

  return (
    <ProTable
      {...MyProTableProps.props}
      headerTitle="房屋关联车位"
      request={async (params, sort) =>
        MyProTableProps.request(
          {
            ...params,
            asset_houses_id: item.id,
          },
          sort,
          Apis.Asset.AssetCarPorts.List,
        )
      }
      search={false}
      columns={[
        MyColumns.ID({
          search: false,
        }),
        {
          title: '车场名称',
          dataIndex: ['asset_parking_place', 'name'],
          search: false,
        },
        {
          title: '车位号',
          dataIndex: 'name',
          search: false,
        },
        {
          title: '车位全称',
          dataIndex: 'full_name',
          search: false,
        },
        {
          title: '建筑面积',
          dataIndex: 'built_area',
          search: false,
        },
        MyColumns.EnumTag({
          title: '类型',
          dataIndex: 'type',
          valueEnum: AssetCarPortsTypeEnum,
          search: false,
        }),
        MyColumns.EnumTag({
          title: '产权类型',
          dataIndex: 'property_type',
          valueEnum: AssetCarPortsPropertyTypeEnum,
          search: false,
        }),
        MyColumns.EnumTag({
          title: '状态',
          dataIndex: 'status',
          valueEnum: AssetCarPortsStatusEnum,
          search: false,
        }),
        MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>
              <SpaceShow item={item} title="车位详情" />
            </Space>
          ),
        }),
      ]}
    />
  );
}
