const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_locales = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
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/pro/numberKeyboard/index.tsx
const NumberKeyboard = (props) => {
	var _context$engine;
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_locales.default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	const [num, setNum] = (0, react.useState)((props === null || props === void 0 ? void 0 : props.value) || "");
	const KeyboardItems = (0, 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 || props === void 0 ? void 0 : props.deleteText) || /* @__PURE__ */ react.default.createElement(_pisell_icon_es_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 || props === void 0 ? void 0 : props.okText) || _pisell_utils.locales.getText("pisell2.number.keyboard.ok"),
				disabled: false,
				type: "primary"
			}
		];
	}, [
		_pisell_utils.locales,
		props === null || props === void 0 ? void 0 : props.okText,
		props === null || props === void 0 ? void 0 : props.deleteText
	]);
	const handleKeyboardChange = (e) => {
		if (e === "ok") {
			var _props$onOk;
			props === null || props === void 0 || (_props$onOk = props.onOk) === null || _props$onOk === void 0 || _props$onOk.call(props);
		} else if (e === "delete") {
			var _props$onDelete;
			if (num.length === 0) return;
			const newNum = num.slice(0, -1);
			setNum(newNum);
			props === null || props === void 0 || (_props$onDelete = props.onDelete) === null || _props$onDelete === void 0 || _props$onDelete.call(props, newNum);
		} else {
			var _props$onChange;
			if ((props === null || props === void 0 ? void 0 : props.maxLength) && num.length >= (props === null || props === void 0 ? void 0 : props.maxLength)) {
				console.log("input_maxLength_over", props === null || props === void 0 ? void 0 : props.maxLength, num);
				return;
			}
			const newNum = num + e;
			if ((props === null || props === void 0 ? void 0 : props.max) && parseInt(newNum) > props.max) {
				console.log("input_maxValue_over", props === null || props === void 0 ? void 0 : props.max, newNum);
				return;
			}
			setNum(newNum);
			props === null || props === void 0 || (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newNum);
		}
	};
	const handleInputChange = (e) => {
		var _props$onChange2;
		const newNum = e.target.value;
		if ((props === null || props === void 0 ? void 0 : props.max) && parseInt(newNum) > props.max) return;
		setNum(newNum);
		props === null || props === void 0 || (_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 || _props$onChange2.call(props, newNum);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-pro-number-keyboard" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.VirtualKeyboard, {
		style: require_objectSpread2._objectSpread2({}, (props === null || props === void 0 ? void 0 : props.style) || {}),
		selectType: "dark",
		keyboardProps: {
			keydown: false,
			items: KeyboardItems,
			onChange: handleKeyboardChange
		},
		virtualKeyInputProps: {
			value: num,
			onChange: handleInputChange,
			placeholder: (props === null || props === void 0 ? void 0 : props.placeholder) || "",
			style: require_objectSpread2._objectSpread2({
				height: "65px",
				fontSize: "36px"
			}, (props === null || props === void 0 ? void 0 : props.inputStyle) || {})
		}
	}));
};
//#endregion
exports.default = NumberKeyboard;
