import { getText } from "../../../locales/index.js";
import VirtualKeyboard from "../index.js";
import { formatStringToTime } from "./utils.js";
import React, { useEffect, useMemo } from "react";
import dayjs from "dayjs";
import "./index.less";
//#region src/components/virtual-keyboard/Time/index.tsx
const 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: "now",
		label: getText("virtual-keyboard-time-now"),
		disabled: false,
		type: "text",
		style: { color: "#7f56d9" }
	},
	{
		value: "0",
		label: "0",
		disabled: false,
		type: "text"
	},
	{
		value: "ok",
		label: getText("virtual-keyboard-time-ok"),
		disabled: false,
		type: "primary"
	}
];
const VirtualKeyboardTime = (props) => {
	const { onChange, onEnter, style, className, value = "", rightPanel } = props;
	useEffect(() => {
		document.body.id = "body";
	}, []);
	const res = useMemo(() => {
		return formatStringToTime(value);
	}, [value]);
	const _onChange = (current) => {
		if (current === "ok") {
			onEnter === null || onEnter === void 0 || onEnter(formatStringToTime(value));
			return;
		}
		if (current === "now") {
			onEnter === null || onEnter === void 0 || onEnter(dayjs().format("HH:mm"));
			return;
		}
		let _val = res.valueString + current;
		if (res.valueString.length === 4) _val = current + "";
		if (document.querySelector(".virtual-keyboard-input-select")) _val = current + "";
		onChange === null || onChange === void 0 || onChange(formatStringToTime(_val));
	};
	return /* @__PURE__ */ React.createElement(VirtualKeyboard, {
		className,
		style,
		keyboardProps: {
			items,
			onChange: (current) => {
				_onChange(current);
			}
		},
		virtualKeyInputProps: {
			value,
			onChange: (e) => {
				onChange === null || onChange === void 0 || onChange(formatStringToTime(e.target.value));
			},
			renderInput: () => {
				return res === null || res === void 0 ? void 0 : res.previewValueArrayDom;
			}
		},
		rightPanel
	});
};
//#endregion
export { VirtualKeyboardTime as default };
