import React, { useCallback, useEffect, useState } from "react";
import styles from "./index.module.scss";
import { Button, Modal } from "antd";
import MyPopconfirm from "@/components/MyPopconfirm";
import { C1_APIgetConfig, C1_APIsetConfig } from "@/store/action/C1orderset";
import TextArea from "antd/es/input/TextArea";
import { MessageFu } from "@/utils/message";

type Props = {
  closeFu: () => void;
};

function C1setTxt({ closeFu }: Props) {
  const [txt, setTxt] = useState("");

  // 点击提交
  const btnOkFu = useCallback(async () => {
    const res = await C1_APIsetConfig({ id: 11, rtf: txt });
    if(res.code===0){
      closeFu()
      MessageFu.success('设置成功!')
    }
  }, [closeFu, txt]);

  const getInfoFu = useCallback(async () => {
    const res = await C1_APIgetConfig(11);
    if (res.code === 0) {
      setTxt(res.data.rtf || "");
    }
  }, []);

  useEffect(() => {
    getInfoFu();
  }, [getInfoFu]);

  return (
    <Modal
      wrapClassName={styles.C1setTxt}
      open={true}
      title="预约需知"
      footer={
        [] // 设置footer为空，去掉 取消 确定默认按钮
      }
    >
      <div className="C1sMain">
        <TextArea
          maxLength={200}
          showCount
          placeholder="请输入内容"
          value={txt}
          onChange={(e) => setTxt(e.target.value)}
        />
      </div>
      <div className="C1sBtn">
        <Button type="primary" onClick={btnOkFu}>
          提交
        </Button>
        &emsp;
        <MyPopconfirm txtK="取消" onConfirm={closeFu} />
      </div>
    </Modal>
  );
}

const MemoC1setTxt = React.memo(C1setTxt);

export default MemoC1setTxt;
