import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  AssetParkingPlacesChargeTypeEnum,
  AssetParkingPlacesLocationTypeEnum,
  AssetParkingPlacesPropertyTypeEnum,
  AssetParkingPlacesTypeEnum,
} from '@/gen/Enums';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { message } from 'antd';

export default function Create(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Asset.AssetParkingPlaces.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      // wrapperCol={{ span: 24 }}
      layout="horizontal"
      labelCol={{ span: 4 }}
      wrapperCol={{ span: 24 }}
      labelAlign="left"
      key={new Date().getTime()}
      width="600px"
      trigger={<MyButtons.Create title={`${props.title}`} />}
      onFinish={async (values) =>
        Apis.Asset.AssetParkingPlaces.Store({
          ...values,
          asset_projects_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'name',
          title: '车场名称',
          formItemProps: { ...rulesHelper.text },
        },
        MyFormItems.EnumRadio({
          key: 'type',
          title: '类型',
          valueEnum: AssetParkingPlacesTypeEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'property_type',
          title: '产权类型',
          valueEnum: AssetParkingPlacesPropertyTypeEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'location_type',
          title: '位置类型',
          valueEnum: AssetParkingPlacesLocationTypeEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'charge_type',
          title: '收费类型',
          valueEnum: AssetParkingPlacesChargeTypeEnum,
          required: true,
        }),
        {
          key: 'import_numbers',
          title: '入口数量',
          colProps: { span: 24 },
        },
        {
          key: 'export_numbers',
          title: '出口数量',
          colProps: { span: 24 },
        },
        // {
        //   key: 'total_spaces',
        //   title: '总车位数',
        //   valueType: 'digit',
        //   colProps: { span: 24 },
        //   width: '100%',
        // },
        {
          key: 'remark',
          title: '备注',
          valueType: 'textarea',
        },
      ]}
    />
  );
}
