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/components/pisellSelectCustomerModal/index.tsx
var pisellSelectCustomerModal_exports = {};
__export(pisellSelectCustomerModal_exports, {
  default: () => pisellSelectCustomerModal_default
});
module.exports = __toCommonJS(pisellSelectCustomerModal_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_antd = require("antd");
var import_RightPanel = __toESM(require("./RightPanel"));
var import_CustomerCard = __toESM(require("./CustomerCard"));
var import_index = require("./index.less");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_locales2 = require("../../utils/locales");
var 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: "+",
    label: "+",
    disabled: false,
    type: "text"
  },
  {
    value: "0",
    label: "0",
    disabled: false,
    type: "text"
  },
  {
    value: "reset",
    label: "Reset",
    disabled: false,
    type: "text"
  }
];
var PisellSelectCustomerModal = (props) => {
  const {
    onChange,
    value,
    popoverProps,
    virtualKeyboardProps,
    keyboardProps,
    virtualKeyInputProps,
    cardProps
  } = props;
  const [open, setOpen] = (0, import_react.useState)(false);
  const [_value, set_value] = (0, import_react.useState)();
  const [phone, setPhone] = (0, import_react.useState)("");
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(import_locales.default, (0, import_locales2.getLocale)());
  (0, import_react.useEffect)(() => {
    set_value(value);
  }, [value]);
  const _onChange = (e) => {
    set_value(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 (!phone) {
      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 = phone;
    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;
  }, [phone]);
  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,
        {
          style: { zoom: 0.8 },
          keyboardProps: {
            keydown: false,
            items,
            onChange: (e) => {
              if (e === "reset") {
                setPhone("");
                return;
              }
              setPhone(phone + String(e));
            },
            ...keyboardProps
          },
          virtualKeyInputProps: {
            value: phone,
            onChange: (e) => {
              setPhone(e.target.value);
            },
            placeholder: import_utils.locales.getText(
              "pisell2.text.search-customer-by-phone-number"
            ),
            style: {
              textAlign: "left",
              fontSize: adjustFontSize
            },
            className: "pisell-select-customer-modal-input",
            ...virtualKeyInputProps
          },
          rightPanel: /* @__PURE__ */ import_react.default.createElement(import_RightPanel.default, { value: _value, phone, onChange: _onChange }),
          ...virtualKeyboardProps
        }
      ),
      open,
      placement: "bottom",
      arrow: false,
      onOpenChange,
      trigger: ["click"],
      ...popoverProps
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_CustomerCard.default,
      {
        onClickItem: () => {
          setOpen(true);
        },
        customer: _value,
        onRemove: _onChange,
        ...cardProps
      }
    )
  ));
};
var pisellSelectCustomerModal_default = PisellSelectCustomerModal;
