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/pisellPriceKeyboardPopover/PisellPriceKeyboardPopover.tsx
var PisellPriceKeyboardPopover_exports = {};
__export(PisellPriceKeyboardPopover_exports, {
  default: () => PisellPriceKeyboardPopover_default
});
module.exports = __toCommonJS(PisellPriceKeyboardPopover_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_PisellPriceKeyboardPopover = require("./PisellPriceKeyboardPopover.less");
var PisellPriceKeyboardPopover = (0, import_react.forwardRef)(
  ({
    children,
    value = "",
    onChange,
    onConfirm,
    onCancel,
    showCurrencySymbol = true,
    useThousandsSeparator = false,
    selectType = "dark",
    disabled = false,
    overlayClassName = "",
    style
  }, ref) => {
    const [open, setOpen] = (0, import_react.useState)(false);
    const [tempValue, setTempValue] = (0, import_react.useState)("");
    const [isFirstInput, setIsFirstInput] = (0, import_react.useState)(true);
    (0, import_react.useImperativeHandle)(ref, () => ({
      open: () => {
        setOpen(true);
        setTempValue(value);
        setIsFirstInput(true);
      },
      close: () => setOpen(false),
      isOpen: () => open
    }));
    const handleOpenChange = (visible) => {
      if (disabled) return;
      setOpen(visible);
      if (visible) {
        setTempValue(value);
        setIsFirstInput(true);
      } else {
        onCancel == null ? void 0 : onCancel();
      }
    };
    const handlePriceChange = (val) => {
      if ((val === "" || val === 0 || val === "0") && !isFirstInput) {
        setIsFirstInput(true);
        setTempValue(val);
        onChange == null ? void 0 : onChange(val);
        return;
      }
      if (isFirstInput && val !== "" && val !== 0 && val !== "0") {
        setIsFirstInput(false);
        const currentValueStr = String(tempValue || "").replace(/[^\d.]/g, "");
        const newValueStr = String(val).replace(/[^\d.]/g, "");
        if (currentValueStr && currentValueStr !== "0" && newValueStr.length > currentValueStr.length && newValueStr.startsWith(currentValueStr)) {
          const newInput = newValueStr.slice(currentValueStr.length);
          if (newInput) {
            setTempValue(newInput);
            onChange == null ? void 0 : onChange(newInput);
            return;
          }
        }
      }
      setTempValue(val);
      onChange == null ? void 0 : onChange(val);
    };
    const handleConfirm = (val) => {
      onConfirm == null ? void 0 : onConfirm(val);
      setOpen(false);
    };
    const handleCancel = () => {
      setOpen(false);
      onCancel == null ? void 0 : onCancel();
    };
    const keyboardContent = /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-price-keyboard-popover-content" }, /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellPriceKeyboard,
      {
        value: tempValue,
        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,
        backgroundColor: "transparent"
      }
    ));
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Popover,
      {
        open,
        content: keyboardContent,
        trigger: disabled ? [] : ["click"],
        overlayInnerStyle: { padding: 0 },
        destroyTooltipOnHide: true,
        arrow: false,
        align: {
          offset: [0, 0]
        },
        overlayClassName: `pisell-price-keyboard-popover ${overlayClassName}`,
        onOpenChange: handleOpenChange,
        overlayStyle: style
      },
      children
    );
  }
);
PisellPriceKeyboardPopover.displayName = "PisellPriceKeyboardPopover";
var PisellPriceKeyboardPopover_default = PisellPriceKeyboardPopover;
