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/pisellPhoneKeyboard/index.tsx
var pisellPhoneKeyboard_exports = {};
__export(pisellPhoneKeyboard_exports, {
  default: () => pisellPhoneKeyboard_default
});
module.exports = __toCommonJS(pisellPhoneKeyboard_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_antd = require("antd");
var import_index = require("./index.less");
var import_Delete = __toESM(require("@pisell/icon/es/Delete"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_locales2 = require("../../utils/locales");
var PisellPhoneKeyboard = (props) => {
  import_utils.locales.init(import_locales.default, (0, import_locales2.getLocale)());
  const {
    onChange,
    value,
    popoverProps,
    virtualKeyboardProps,
    keyboardProps,
    virtualKeyInputProps
  } = props;
  const [open, setOpen] = (0, import_react.useState)(false);
  const items = [
    {
      value: 1,
      label: "1",
      disabled: false,
      type: "text"
    },
    {
      value: 2,
      label: "2",
      disabled: false,
      type: "text"
    },
    {
      value: 3,
      label: "3",
      disabled: false,
      type: "text"
    },
    {
      value: 4,
      label: "4",
      disabled: false,
      type: "text"
    },
    {
      value: 5,
      label: "5",
      disabled: false,
      type: "text"
    },
    {
      value: 6,
      label: "6",
      disabled: false,
      type: "text"
    },
    {
      value: 7,
      label: "7",
      disabled: false,
      type: "text"
    },
    {
      value: 8,
      label: "8",
      disabled: false,
      type: "text"
    },
    {
      value: 9,
      label: "9",
      disabled: false,
      type: "text"
    },
    {
      value: "delete",
      label: /* @__PURE__ */ import_react.default.createElement(import_Delete.default, { className: "virtual-keyboard-input-delete-icon" }),
      disabled: false,
      type: "text"
    },
    {
      value: "0",
      label: "0",
      disabled: false,
      type: "text"
    },
    {
      value: "ok",
      label: import_utils.locales.getText("pisell2.text.confirm"),
      disabled: false,
      type: "primary"
    }
  ];
  const onOk = (e) => {
    onChange == null ? void 0 : onChange(e);
    setOpen(false);
  };
  const onOpenChange = (e) => {
    setOpen(e);
  };
  (0, import_react.useEffect)(() => {
    if (open) {
      document.body.classList.add("hide-scroll");
    } else {
      setTimeout(() => {
        document.body.classList.remove("hide-scroll");
      }, 150);
    }
  }, [open]);
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
  }, []);
  const adjustFontSize = (0, import_react.useMemo)(() => {
    if (!value) {
      return 30;
    }
    const maxFontSize = 60;
    const minFontSize = 10;
    const defaultFontSize = maxFontSize;
    const inputWidth = 248;
    const span = document.createElement("span");
    span.style.position = "absolute";
    span.style.whiteSpace = "nowrap";
    span.style.visibility = "hidden";
    span.style.fontSize = `${defaultFontSize}px`;
    span.textContent = value;
    document.body.appendChild(span);
    let fontSize = maxFontSize;
    while (span.offsetWidth > inputWidth && fontSize > minFontSize) {
      fontSize -= 0.5;
      span.style.fontSize = `${fontSize}px`;
    }
    document.body.removeChild(span);
    return fontSize;
  }, [value]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Popover,
    {
      content: /* @__PURE__ */ import_react.default.createElement(
        import_materials.VirtualKeyboard,
        {
          keyboardProps: {
            keydown: false,
            items,
            onChange: (e) => {
              if (e === "reset") {
                onChange("");
                return;
              }
              if (e === "ok") {
                onOk(value || "");
                return;
              }
              if (e === "delete") {
                onChange((value == null ? void 0 : value.slice(0, -1)) || "");
                return;
              }
              onChange(value + String(e));
            },
            ...keyboardProps
          },
          virtualKeyInputProps: {
            value,
            onChange: (e) => {
              onChange(e.target.value);
            },
            style: {
              textAlign: "left",
              fontSize: adjustFontSize
            },
            ...virtualKeyInputProps
          },
          ...virtualKeyboardProps
        }
      ),
      open,
      arrow: false,
      onOpenChange,
      trigger: ["click"],
      ...popoverProps
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { readOnly: true, value, style: { width: "100%" }, size: "large" })
  ));
};
var pisellPhoneKeyboard_default = PisellPhoneKeyboard;
