import { PlusOutlined } from '@ant-design/icons';
import {
  ModalForm,
  ProForm,
  ProFormDateRangePicker,
  ProFormSelect,
  ProFormText,
  ProFormDigit,
} from '@ant-design/pro-components';
import React, {useEffect} from "react";
import { Button, Form, message, InputNumber } from 'antd';
import {DictOptionType, DictValueEnumObj} from "@/components/DictTag";

export type ListFormProps = {
  onCancel: (flag?: boolean, formVals?: unknown) => void;
  onSubmit: (values:  API.AreaBusiness.CircleEditParams) => Promise<void>;
  open: boolean;
  values?: Partial< API.AreaBusiness.CircleEditParams>;
  jobGroupOptions?: DictOptionType[];
  statusOptions?: DictValueEnumObj;
};

const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

const SubWayEdit: React.FC<ListFormProps> = (props) => {
  const [form] = Form.useForm();
  useEffect(() => {
    form.resetFields();
    if(props.values) {
      form.setFieldsValue({
        commercialAreaId: props.values.commercialAreaId,
        commercialAreaName: props.values.commercialAreaName,
        latitude: props.values.latitude,
        longitude: props.values.longitude,
      });
    }
  }, [form, props]);
  const handleCancel = () => {
    props.onCancel();
    form.resetFields();
  };

  const handleFinish = async (values: Record<string, any>) => {
    console.log(values)
    props.onSubmit(values as API.AreaBusiness.CircleEditParams);
  };

  return (
    <ModalForm<API.AreaBusiness.CircleParams>
      title="新增线路"
      form={form}
      // layout="inline"
      autoFocusFirstInput
      open={props.open}
      modalProps={{
        destroyOnClose: true,
        onCancel: () => handleCancel(),
      }}
      submitTimeout={2000}
      onFinish={handleFinish}
    >
      <ProFormDigit
        name="commercialAreaId"
        label={'字典主键'}
        placeholder="请输入字典主键"
        disabled
        hidden={true}
      />
      <ProForm.Group>
        <ProFormText
          width="md"
          name="commercialAreaName"
          label="商圈名称"
          placeholder="请输入名称"
          rules={[
            {
              required: true,
              message: "请输入商圈名称！" ,
            },
          ]}
        />
      </ProForm.Group>
      <ProForm.Group>
        <ProFormDigit
          label="纬度"
          placeholder="请输入纬度"
          name="latitude"
          width="md"
          min={-90}
          max={90}
          fieldProps={{ controls: false }}
          rules={[
            {
              required: true,
              message: "请输入纬度！" ,
            },
          ]}
        />
        <ProFormDigit
          label="经度"
          placeholder="请输入经度"
          name="longitude"
          width="md"
          min={-180}
          max={180}
          fieldProps={{ controls: false }}
          rules={[
            {
              required: true,
              message: "请输入经度！" ,
            },
          ]}
        />
      </ProForm.Group>
    </ModalForm>
  );
};

export default SubWayEdit
