import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  MyTableActions,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import {
  AssetParkingPlacesChargeTypeEnum,
  AssetParkingPlacesLocationTypeEnum,
  AssetParkingPlacesPropertyTypeEnum,
  AssetParkingPlacesTypeEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';
import Update from './modals/AreaUpdate';

export default function Index({ title = '车场车位' }) {
  const navigate = useNavigate();
  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="asset_parking_places"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        headerTitle="车场列表"
        tooltip="车场列表的信息管理，请在【项目列表】的【配置】中进行操作"
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Asset.AssetParkingPlaces.List,
          )
        }
        // toolBarRender={(action) => [
        //   <Create key="Create" reload={action?.reload} title="车场" />,
        // ]}
        columns={[
          MyColumns.ID({ search: false }),
          Selects?.AssetProjects({
            title: '选择项目',
            key: 'asset_projects_id',
            hidden: true,
          }),
          {
            title: '项目名称',
            dataIndex: ['asset_project', 'name'],
            search: false,
            // search: {
            //   transform: (value) => {
            //     return { project_name: value };
            //   },
            // },
          },
          {
            title: '车场名称',
            dataIndex: 'name',
          },

          MyColumns.EnumTag({
            title: '车场类型',
            dataIndex: 'type',
            valueEnum: AssetParkingPlacesTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '产权类型',
            dataIndex: 'property_type',
            valueEnum: AssetParkingPlacesPropertyTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '位置类型',
            dataIndex: 'location_type',
            valueEnum: AssetParkingPlacesLocationTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '收费类型',
            dataIndex: 'charge_type',
            valueEnum: AssetParkingPlacesChargeTypeEnum,
          }),
          {
            title: '入口数量',
            dataIndex: 'import_numbers',
            search: false,
          },
          {
            title: '出口数量',
            dataIndex: 'export_numbers',
            search: false,
          },
          {
            title: '车位数量',
            dataIndex: 'total_spaces',
            search: false,
          },
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.Default
                  size="small"
                  type="primary"
                  title="查看车位"
                  onClick={() => {
                    navigate(`/asset/parking_area/show/${item.id}`);
                    console.log(item);
                  }}
                />
                <MyTableActions
                  actions={{
                    update: (
                      <Update
                        item={item}
                        reload={action?.reload}
                        title={title}
                      />
                    ),
                    delete: (
                      <MyButtons.Delete
                        onConfirm={() =>
                          Apis.Asset.AssetParkingPlaces.Delete({
                            id: item.id,
                          }).then(() => action?.reload())
                        }
                      />
                    ),
                  }}
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
