import { FC } from "react";
import { Form, Input, InputNumber, Modal, ModalProps } from "antd";
import style from "@/components/AddIndexModal/index.module.scss";

export interface EvaluationModalProps extends Omit<ModalProps, "onOk"> {
  onCancel?: () => void;
  onOk?: (val: any) => void;
}

const { TextArea } = Input;

export const EvaluationModal: FC<EvaluationModalProps> = ({
  open,
  onOk,
  onCancel,
  ...rest
}) => {
  const [form] = Form.useForm<any>();

  const handleCancel = () => {
    form.resetFields();
    onCancel?.();
  };

  const handleConfirm = () => {
    form.submit();
  };

  const handleSubmit = async (values: any) => {
    onOk?.(values);
    handleCancel();
  };

  return (
    <Modal
      className={style.modal}
      title="附加项评定"
      okText="提交"
      cancelText="取消"
      open={open}
      width={640}
      okButtonProps={{
        disabled: false,
      }}
      onOk={handleConfirm}
      onCancel={handleCancel}
      {...rest}
    >
      <Form
        labelCol={{ span: 4, offset: 2 }}
        form={form}
        onFinish={handleSubmit}
      >
        <Form.Item
          label="评定得分"
          name="checkedKeys"
          required
          rules={[{ required: true, message: "请输入 " }]}
        >
          <InputNumber
            className="w100"
            min={0}
            max={50}
            precision={1}
            placeholder="请输入0~50的数字，支持小数点后一位"
          />
        </Form.Item>
        <Form.Item label="评定意见">
          <TextArea
            rows={4}
            maxLength={200}
            placeholder="请输入内容，不超过200字"
          />
        </Form.Item>
      </Form>
    </Modal>
  );
};
