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/virtual-keyboard/BaseNumberKeyboard/index.tsx
var BaseNumberKeyboard_exports = {};
__export(BaseNumberKeyboard_exports, {
  default: () => BaseNumberKeyboard_default
});
module.exports = __toCommonJS(BaseNumberKeyboard_exports);
var import_react = __toESM(require("react"));
var import_Delete = __toESM(require("@pisell/icon/es/Delete"));
var import_ahooks = require("ahooks");
var import_utils = require("@pisell/utils");
var import_Presets = __toESM(require("./Presets"));
var import_Keyboard = __toESM(require("../Keyboard"));
var import_VirtualKeyInput = __toESM(require("../VirtualKeyInput"));
var import_VirtualInput = __toESM(require("../VirtualInput"));
var import_index = require("./index.less");
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: "0",
    label: "0",
    disabled: false,
    type: "text"
  },
  {
    value: "00",
    label: "00",
    disabled: false,
    type: "text"
  },
  {
    value: ".",
    label: ".",
    disabled: false,
    type: "text"
  }
];
var BaseNumberKeyboard = (props) => {
  const {
    onChange,
    placeholder,
    format,
    defaultValue = "",
    doneText,
    resetText,
    max,
    min,
    onEnter,
    presets,
    defaultSelect
  } = props;
  const [value, setValue] = (0, import_ahooks.useControllableValue)(props, {
    defaultValue
  });
  const [select, setSelect] = (0, import_react.useState)(defaultSelect ?? false);
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
  }, []);
  const rightItems = (0, import_react.useMemo)(() => {
    return [
      {
        value: "delete",
        label: /* @__PURE__ */ import_react.default.createElement(import_Delete.default, { className: "virtual-keyboard-input-delete-icon" }),
        disabled: false,
        type: "text"
      },
      {
        value: "reset",
        label: resetText || "Reset",
        disabled: false,
        type: "text",
        style: {
          fontSize: "18px",
          color: "#D92D20"
        }
      },
      {
        value: "done",
        label: doneText || "Done",
        disabled: false,
        type: "primary",
        size: 2,
        style: {
          fontSize: "18px",
          background: "var(--Green-light-600, #4CA30D)",
          color: "#fff"
        }
      }
    ];
  }, [doneText, resetText]);
  const checkValue = (val) => {
    if ((0, import_utils.isNumber)(max) && Number(val) > max) {
      const newValue = Math.min(Number(val), Number(max));
      setValue(`${newValue}`);
      return { message: "" };
    }
    if ((0, import_utils.isNumber)(min) && Number(val) < min) {
      const newValue = Math.max(Number(val), Number(min));
      setValue(`${newValue}`);
      return { message: "" };
    }
  };
  const handleChangeValue = (val) => {
    const detail = checkValue(val);
    if (detail)
      return;
    setValue(val);
  };
  const actions = {
    ".": (val) => {
      if (value.includes("."))
        return;
      actions.default(val);
    },
    delete: () => {
      handleChangeValue(select ? "" : `${value || ""}`.slice(0, -1));
    },
    reset: () => {
      handleChangeValue(`${defaultValue || ""}` || "");
    },
    done: () => {
      onEnter == null ? void 0 : onEnter(value);
    },
    ok: () => {
      onEnter == null ? void 0 : onEnter(value);
    },
    default: (val) => {
      handleChangeValue(select ? `${val}` : `${value}${val}`);
    }
  };
  const handleKeyboardChange = (0, import_ahooks.useMemoizedFn)((val) => {
    return (actions[val] || actions.default)(val);
  });
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-virtual-keyboard-base" }, /* @__PURE__ */ import_react.default.createElement(
    import_VirtualKeyInput.default,
    {
      value,
      onChange: (e) => handleChangeValue(e.target.value),
      renderInput: (props2) => {
        if ((0, import_utils.isUndefined)(props2.value) || props2.value === "") {
          return /* @__PURE__ */ import_react.default.createElement(
            import_VirtualInput.default,
            {
              autoFocus: true,
              placeholder,
              value: props2.value
            }
          );
        }
        return (format == null ? void 0 : format(props2.value)) || props2.value;
      },
      showDelete: false,
      onValueSelect: setSelect,
      defaultSelect
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_Presets.default, { presets, onChange: handleChangeValue }), /* @__PURE__ */ import_react.default.createElement(
    import_Keyboard.default,
    {
      items,
      rightItems,
      onChange: handleKeyboardChange
    }
  ));
};
var BaseNumberKeyboard_default = BaseNumberKeyboard;
