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

export default function Update(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Asset.AssetParkingPlaces.Update>
      {...MyModalFormProps.props}
      title={`编辑${props.title}`}
      trigger={<MyButtons.Edit title={props.item?.titl} type="link" />}
      // wrapperCol={{ span: 24 }}
      layout="horizontal"
      labelCol={{ span: 4 }}
      wrapperCol={{ span: 24 }}
      labelAlign="left"
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue(props.item);
        }
      }}
      onFinish={async (values) =>
        Apis.Asset.AssetParkingPlaces.Update({
          ...values,
          id: props.item?.id ?? 0,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        Selects?.AssetProjects({
          key: 'asset_projects_id',
          title: '选择项目',
          colProps: { span: 24 },
          required: true,
        }),
        {
          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: 'remark',
          title: '备注',
          valueType: 'textarea',
        },
      ]}
    />
  );
}
