import { MyButtons, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';

import {
  AssetCarPortsPropertyTypeEnum,
  AssetCarPortsStatusEnum,
  AssetCarPortsTypeEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useEffect, useRef } from 'react';
import ChargeStandardHasCar from '../modals/ChargeStandardHasCar';

export default function Index({ ...rest }) {
  const actionLooks = useRef<any>();
  useEffect(() => {
    actionLooks?.current.reloadAndRest();
  }, [rest.loadmore]);

  return (
    <>
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        headerTitle="已绑定车位"
        actionRef={actionLooks}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              house_charge_standards_id: rest.item?.house_charge_has_houses_id,
            },
            sort,
            Apis.HouseCharge.HouseChargeHasCarPorts.List,
          )
        }
        toolBarRender={(action) => [
          <ChargeStandardHasCar
            item={{
              ...rest.item,
              size: 'middle',
            }}
            reload={action?.reload}
            title={'绑车位'}
          />,
        ]}
        search={false}
        columns={[
          // MyColumns.ID({
          //   search: false,
          // }),
          {
            title: '车场名称',
            dataIndex: ['asset_parking_place', 'name'],
            search: {
              transform: (value) => {
                return { parking_place_name: value };
              },
            },
          },
          {
            title: '车位号',
            dataIndex: ['asset_car_port', 'name'],
            search: false,
          },
          // {
          //   title: '车位全称',
          //   dataIndex: ['asset_car_port', 'full_name'],
          // },
          {
            title: '建筑面积',
            dataIndex: ['asset_car_port', 'built_area'],
            search: false,
          },
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: ['asset_car_port', 'type'],
            valueEnum: AssetCarPortsTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '产权类型',
            dataIndex: ['asset_car_port', 'property_type'],
            valueEnum: AssetCarPortsPropertyTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: ['asset_car_port', 'status'],
            valueEnum: AssetCarPortsStatusEnum,
          }),
          {
            title: '绑定时间',
            dataIndex: 'updated_at',
            search: false,
          },
          MyColumns.Option({
            width: 80,
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.HouseCharge.HouseChargeHasCarPorts.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
