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/numberKeyboard/index.tsx
var numberKeyboard_exports = {};
__export(numberKeyboard_exports, {
  default: () => numberKeyboard_default
});
module.exports = __toCommonJS(numberKeyboard_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_Delete = __toESM(require("@pisell/icon/es/Delete"));
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_index = require("./index.less");
var NumberKeyboard = (props) => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  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 [num, setNum] = (0, import_react.useState)((props == null ? void 0 : props.value) || "");
  const KeyboardItems = (0, import_react.useMemo)(() => {
    return [
      {
        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: (props == null ? void 0 : props.deleteText) || /* @__PURE__ */ import_react.default.createElement(import_Delete.default, { className: "virtual-keyboard-input-delete-icon-num" }),
        disabled: false,
        type: "text"
      },
      {
        value: 0,
        label: "0",
        disabled: false,
        type: "text"
      },
      {
        value: "ok",
        label: (props == null ? void 0 : props.okText) || import_utils.locales.getText("pisell2.number.keyboard.ok"),
        disabled: false,
        type: "primary"
      }
    ];
  }, [import_utils.locales, props == null ? void 0 : props.okText, props == null ? void 0 : props.deleteText]);
  const handleKeyboardChange = (e) => {
    var _a2, _b2, _c;
    if (e === "ok") {
      (_a2 = props == null ? void 0 : props.onOk) == null ? void 0 : _a2.call(props);
    } else if (e === "delete") {
      if (num.length === 0) {
        return;
      }
      const newNum = num.slice(0, -1);
      setNum(newNum);
      (_b2 = props == null ? void 0 : props.onDelete) == null ? void 0 : _b2.call(props, newNum);
    } else {
      if ((props == null ? void 0 : props.maxLength) && num.length >= (props == null ? void 0 : props.maxLength)) {
        console.log("input_maxLength_over", props == null ? void 0 : props.maxLength, num);
        return;
      }
      const newNum = num + e;
      if ((props == null ? void 0 : props.max) && parseInt(newNum) > props.max) {
        console.log("input_maxValue_over", props == null ? void 0 : props.max, newNum);
        return;
      }
      setNum(newNum);
      (_c = props == null ? void 0 : props.onChange) == null ? void 0 : _c.call(props, newNum);
    }
  };
  const handleInputChange = (e) => {
    var _a2;
    const newNum = e.target.value;
    if ((props == null ? void 0 : props.max) && parseInt(newNum) > props.max) {
      return;
    }
    setNum(newNum);
    (_a2 = props == null ? void 0 : props.onChange) == null ? void 0 : _a2.call(props, newNum);
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-pro-number-keyboard" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.VirtualKeyboard,
    {
      style: {
        ...(props == null ? void 0 : props.style) || {}
      },
      selectType: "dark",
      keyboardProps: {
        keydown: false,
        items: KeyboardItems,
        onChange: handleKeyboardChange
      },
      virtualKeyInputProps: {
        value: num,
        onChange: handleInputChange,
        placeholder: (props == null ? void 0 : props.placeholder) || "",
        style: {
          height: "65px",
          fontSize: "36px",
          ...(props == null ? void 0 : props.inputStyle) || {}
        }
      }
    }
  ));
};
var numberKeyboard_default = NumberKeyboard;
