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/VirtualKeyInput/index.tsx
var VirtualKeyInput_exports = {};
__export(VirtualKeyInput_exports, {
  default: () => VirtualKeyInput_default
});
module.exports = __toCommonJS(VirtualKeyInput_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_Delete = __toESM(require("@pisell/icon/es/Delete"));
var import_ahooks = require("ahooks");
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var list = ["Backspace"];
var VirtualKeyInput = (props) => {
  var _a;
  const {
    previewValue = props.value,
    value,
    showDelete = true,
    onValueSelect,
    defaultSelect,
    style
  } = props;
  const [select, setSelect] = (0, import_react.useState)(defaultSelect ?? false);
  (0, import_ahooks.useEventListener)("keydown", (ev) => {
    if (list.includes(ev.key)) {
      _onDelete == null ? void 0 : _onDelete();
    }
  });
  const handleSelectChange = (selected) => {
    onValueSelect == null ? void 0 : onValueSelect(selected);
    setSelect(selected);
  };
  (0, import_ahooks.useUpdateEffect)(() => {
    handleSelectChange(false);
  }, [value]);
  const _onDelete = () => {
    var _a2;
    if (select) {
      (_a2 = props.onChange) == null ? void 0 : _a2.call(props, { target: { value: "" } });
      handleSelectChange(false);
      return;
    }
    let _val = props.value + "";
    _val = _val.slice(0, _val.length - 1);
    props.onChange && props.onChange({ target: { value: _val } });
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "virtual-keyboard-input-wrap",
      style: {
        backgroundColor: (style == null ? void 0 : style.backgroundColor) || "#ffffff"
      }
    },
    props.renderInput ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)("virtual-keyboard-input", {
          "virtual-keyboard-input-select": select
        }),
        onClick: () => {
          if (value) {
            handleSelectChange(!select);
          }
        },
        style: {
          color: (style == null ? void 0 : style.color) || "#000000"
        }
      },
      props.renderInput(props)
    ) : /* @__PURE__ */ import_react.default.createElement(
      import_antd.Input,
      {
        className: "virtual-keyboard-input",
        bordered: false,
        ...props,
        readOnly: true,
        value: previewValue
      }
    ),
    ((_a = `${value ?? ""}`) == null ? void 0 : _a.length) && showDelete ? /* @__PURE__ */ import_react.default.createElement("div", { className: "virtual-keyboard-input-delete", onClick: _onDelete }, /* @__PURE__ */ import_react.default.createElement(import_Delete.default, { className: "virtual-keyboard-input-delete-icon" })) : null
  );
};
var VirtualKeyInput_default = VirtualKeyInput;
