const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
let _pisell_icon_es_Delete = require("@pisell/icon/es/Delete");
_pisell_icon_es_Delete = require_runtime.__toESM(_pisell_icon_es_Delete);
require("./index.less");
//#region src/components/virtual-keyboard/VirtualKeyInput/index.tsx
const list = ["Backspace"];
const VirtualKeyInput = (props) => {
	var _ref;
	const { previewValue = props.value, value, showDelete = true, onValueSelect, defaultSelect, style } = props;
	const [select, setSelect] = (0, react.useState)(defaultSelect !== null && defaultSelect !== void 0 ? defaultSelect : false);
	(0, ahooks.useEventListener)("keydown", (ev) => {
		if (list.includes(ev.key)) _onDelete === null || _onDelete === void 0 || _onDelete();
	});
	const handleSelectChange = (selected) => {
		onValueSelect === null || onValueSelect === void 0 || onValueSelect(selected);
		setSelect(selected);
	};
	(0, ahooks.useUpdateEffect)(() => {
		handleSelectChange(false);
	}, [value]);
	const _onDelete = () => {
		if (select) {
			var _props$onChange;
			(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.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__ */ react.default.createElement("div", {
		className: "virtual-keyboard-input-wrap",
		style: { backgroundColor: (style === null || style === void 0 ? void 0 : style.backgroundColor) || "#ffffff" }
	}, props.renderInput ? /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("virtual-keyboard-input", { "virtual-keyboard-input-select": select }),
		onClick: () => {
			if (value) handleSelectChange(!select);
		},
		style: { color: (style === null || style === void 0 ? void 0 : style.color) || "#000000" }
	}, props.renderInput(props)) : /* @__PURE__ */ react.default.createElement(antd.Input, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
		className: "virtual-keyboard-input",
		bordered: false
	}, props), {}, {
		readOnly: true,
		value: previewValue
	})), ((_ref = `${value !== null && value !== void 0 ? value : ""}`) === null || _ref === void 0 ? void 0 : _ref.length) && showDelete ? /* @__PURE__ */ react.default.createElement("div", {
		className: "virtual-keyboard-input-delete",
		onClick: _onDelete
	}, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Delete.default, { className: "virtual-keyboard-input-delete-icon" })) : null);
};
//#endregion
exports.default = VirtualKeyInput;
