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/pro/pisellPriceKeyboardModal/PisellPriceKeyboardModal.tsx
var PisellPriceKeyboardModal_exports = {};
__export(PisellPriceKeyboardModal_exports, {
  default: () => PisellPriceKeyboardModal_default
});
module.exports = __toCommonJS(PisellPriceKeyboardModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_PisellPriceKeyboardModal = require("./PisellPriceKeyboardModal.less");
var PisellPriceKeyboardModal = ({
  visible = false,
  value = "",
  onChange,
  onClose,
  triggerRef,
  showCurrencySymbol = true,
  useThousandsSeparator = false,
  className,
  style
}) => {
  const [keyboardPosition, setKeyboardPosition] = (0, import_react.useState)({ top: 0, left: 0 });
  const keyboardRef = (0, import_react.useRef)(null);
  const calculatePosition = () => {
    if (!(triggerRef == null ? void 0 : triggerRef.current)) return;
    const rect = triggerRef.current.getBoundingClientRect();
    const keyboardWidth = 360;
    const keyboardHeight = 405;
    const viewportWidth = window.innerWidth;
    const viewportHeight = window.innerHeight;
    let top = rect.bottom + window.scrollY + 8;
    let left = rect.left + window.scrollX;
    if (left + keyboardWidth > viewportWidth) {
      left = viewportWidth - keyboardWidth - 16;
    }
    if (left < 16) {
      left = 16;
    }
    if (top + keyboardHeight > viewportHeight + window.scrollY) {
      top = rect.top + window.scrollY - keyboardHeight - 8;
    }
    if (top < window.scrollY + 16) {
      top = window.scrollY + 16;
    }
    setKeyboardPosition({ top, left });
  };
  (0, import_react.useEffect)(() => {
    if (visible) {
      calculatePosition();
    }
  }, [visible, triggerRef]);
  (0, import_react.useEffect)(() => {
    const handleClickOutside = (event) => {
      var _a;
      if (visible && keyboardRef.current && !keyboardRef.current.contains(event.target) && !((_a = triggerRef == null ? void 0 : triggerRef.current) == null ? void 0 : _a.contains(event.target))) {
        onClose == null ? void 0 : onClose();
      }
    };
    if (visible) {
      document.addEventListener("mousedown", handleClickOutside);
    }
    return () => {
      document.removeEventListener("mousedown", handleClickOutside);
    };
  }, [visible, onClose, triggerRef]);
  const handlePriceChange = (val) => {
    onChange == null ? void 0 : onChange(val);
  };
  const handleConfirm = (val) => {
    onChange == null ? void 0 : onChange(val);
    onClose == null ? void 0 : onClose();
  };
  if (!visible) return null;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        position: "fixed",
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
        zIndex: 1e3,
        pointerEvents: "none"
        // 让背景不响应点击
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Modal,
      {
        open: true,
        onCancel: onClose,
        footer: null,
        closable: false,
        centered: false,
        mask: false,
        className: `pisell-price-keyboard-modal positioned ${className || ""}`,
        getContainer: false,
        style: {
          position: "absolute",
          top: keyboardPosition.top,
          left: keyboardPosition.left,
          margin: 0,
          pointerEvents: "auto",
          // Modal内容可以响应点击
          ...style
        },
        modalRender: (modal) => /* @__PURE__ */ import_react.default.createElement("div", { ref: keyboardRef }, modal)
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellPriceKeyboard,
        {
          value,
          onChange: handlePriceChange,
          onEnter: handleConfirm,
          doneText: import_utils.locales.getText("pisell2.customise-item.save"),
          resetText: import_utils.locales.getText("pisell2.booking.info.text.clear"),
          amountProps: {
            showCurrencySymbol,
            useThousandsSeparator
          },
          selectType: "dark",
          backgroundColor: "transparent"
        }
      )
    )
  );
};
var PisellPriceKeyboardModal_default = PisellPriceKeyboardModal;
