var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/noteModal/index.tsx
var noteModal_exports = {};
__export(noteModal_exports, {
  NoteModalContent: () => NoteModalContent,
  default: () => noteModal_default
});
module.exports = __toCommonJS(noteModal_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_Delete_wght300_24px = __toESM(require("@pisell/icon/es/Delete_wght300_24px"));
var import_AddTempModal = __toESM(require("./AddTempModal"));
var import_index = require("./index.less");
var import_locales = __toESM(require("./locales"));
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_compensatedPisellContainer = __toESM(require("../../pro/compensatedPisellContainer"));
var import_responsive = require("../../responsive");
var { TextArea } = import_materials.Input;
var STORAGE_KEY = "pisell2_note_templates";
var NoteModalContent = ({
  open = false,
  title = "",
  value = "",
  onConfirm,
  onDelete,
  onCancel,
  zIndex,
  variant
}) => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  const isPhoneVariant = variant === "phone";
  import_utils.locales.init(import_locales.default, ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  const [noteValue, setNoteValue] = (0, import_react.useState)(value);
  const [templates, setTemplates] = (0, import_react.useState)([]);
  const [templateModalOpen, setTemplateModalOpen] = (0, import_react.useState)(false);
  const inputRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    if (open) {
      const storedTemplates = localStorage.getItem(STORAGE_KEY);
      if (storedTemplates) {
        try {
          setTemplates(JSON.parse(storedTemplates));
        } catch (error) {
          console.error("Failed to parse templates from localStorage:", error);
          setTemplates([]);
        }
      }
      setTimeout(() => {
        var _a2;
        (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
      }, 100);
    }
  }, [open]);
  const saveTemplates = (newTemplates) => {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(newTemplates));
    setTemplates(newTemplates);
  };
  const handleTemplateClick = (template) => {
    setNoteValue((prev) => (prev || "") + " " + (template || ""));
  };
  const handleConfirm = () => {
    onConfirm == null ? void 0 : onConfirm(noteValue);
  };
  const handleDelete = () => {
    setNoteValue("");
    onDelete == null ? void 0 : onDelete();
  };
  const handleCancel = () => {
    setNoteValue("");
    onCancel == null ? void 0 : onCancel();
  };
  const onAddTemplate = () => {
    setTemplateModalOpen(true);
  };
  const onAddTemplateConfirm = (newTemplate) => {
    if (newTemplate.trim()) {
      const updatedTemplates = [...templates, newTemplate.trim()];
      saveTemplates(updatedTemplates);
      setTemplateModalOpen(false);
    }
  };
  const onAddTemplateCancel = () => {
    setTemplateModalOpen(false);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_compensatedPisellContainer.default,
    {
      renderType: isPhoneVariant ? "drawer" : "modal",
      showHandlerBar: isPhoneVariant,
      props: isPhoneVariant ? {
        open,
        title: title || import_utils.locales.getText("pisell2.text.note.modal.title"),
        placement: "bottom",
        width: "100%",
        height: "auto",
        onClose: handleCancel,
        footer: null,
        destroyOnClose: true,
        zIndex
      } : {
        open,
        title: title || import_utils.locales.getText("pisell2.text.note.modal.title"),
        headerDivider: false,
        onCancel: handleCancel,
        footer: null,
        width: 680,
        centered: true,
        destroyOnClose: true,
        zIndex
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "note-modal-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "template-section" }, /* @__PURE__ */ import_react.default.createElement("div", { onClick: onAddTemplate, className: "add-template-btn" }, import_utils.locales.getText("pisell2.text.note.modal.btn.add.template")), /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "note-modal-templates-container",
        onTouchMove: (e) => e.stopPropagation()
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "note-modal-templates-scroll" }, templates.map((template, index) => /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          key: index,
          style: { display: "inline-block", marginLeft: "8px" }
        },
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: "note-modal-template-tag",
            onClick: () => handleTemplateClick(template)
          },
          template
        )
      )))
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "input-section" }, /* @__PURE__ */ import_react.default.createElement(
      TextArea,
      {
        value: noteValue,
        onChange: (e) => setNoteValue(e.target.value),
        placeholder: import_utils.locales.getText(
          "pisell2.text.note.modal.placeholder"
        ),
        autoSize: { minRows: 4, maxRows: 8 },
        className: "note-input",
        ref: inputRef
      }
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "action-buttons" }, !!value ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        block: true,
        type: "primary",
        danger: true,
        icon: /* @__PURE__ */ import_react.default.createElement("span", { style: { fontSize: 20 } }, /* @__PURE__ */ import_react.default.createElement(import_Delete_wght300_24px.default, null)),
        onClick: handleDelete,
        className: "delete-btn"
      },
      import_utils.locales.getText("pisell2.text.note.modal.btn.delete")
    ) : /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        block: true,
        type: "default",
        onClick: handleCancel,
        className: "delete-btn"
      },
      import_utils.locales.getText("pisell2.text.note.modal.btn.cancel")
    ), /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        block: true,
        type: "primary",
        onClick: handleConfirm,
        className: "confirm-btn",
        disabled: !noteValue
      },
      import_utils.locales.getText("pisell2.text.note.modal.btn.confirm")
    )))
  ), templateModalOpen && /* @__PURE__ */ import_react.default.createElement(
    import_AddTempModal.default,
    {
      open: templateModalOpen,
      onCancel: onAddTemplateCancel,
      onConfirm: onAddTemplateConfirm,
      variant
    }
  ));
};
var NoteModal = (props) => {
  if (!props.open) {
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement(NoteModalContent, { ...props });
};
NoteModal.displayName = "NoteModal";
var noteModal_default = (0, import_responsive.withResponsive)(NoteModal);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  NoteModalContent
});
