const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("../virtual-keyboard/Time/index.js");
const require_index$1 = require("./RightPanel/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
require("./index.less");
//#region src/components/select-time/index.tsx
const SelectTime = (props) => {
	const { onChange, value, popoverProps, timePickerProps, timeProps, slice } = props;
	const [open, setOpen] = (0, react.useState)(false);
	const [_value, set_value] = (0, react.useState)("");
	(0, react.useEffect)(() => {
		set_value(value);
	}, [value]);
	const valueString = (0, react.useMemo)(() => {
		if (!_value) return;
		if (typeof _value === "string") return _value;
		return _value === null || _value === void 0 ? void 0 : _value.valueString;
	}, [_value]);
	const previewValueString = (0, react.useMemo)(() => {
		if (!_value) return null;
		if (typeof _value === "string") return _value;
		return _value === null || _value === void 0 ? void 0 : _value.previewValueString;
	}, [_value]);
	const timePickerValue = (0, react.useMemo)(() => {
		if (!previewValueString) return;
		return (0, dayjs.default)((0, dayjs.default)().format("YYYY-MM-DD") + " " + previewValueString);
	}, [previewValueString]);
	const _onChange = (e) => {
		if (!open) return;
		set_value(e);
	};
	const onEnter = (e) => {
		_onChange(e);
		onOpenChange(false, (e === null || e === void 0 ? void 0 : e.previewValueString) || e);
	};
	const onOpenChange = (e, _val = previewValueString) => {
		setOpen(e);
		if (e) {} else {
			if (_val === value) return;
			onChange === null || onChange === void 0 || onChange(_val);
		}
	};
	(0, react.useEffect)(() => {
		if (open) document.body.classList.add("hide-scroll");
		else setTimeout(() => {
			document.body.classList.remove("hide-scroll");
		}, 150);
	}, [open]);
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(antd.Popover, require_objectSpread2._objectSpread2({
		destroyTooltipOnHide: true,
		content: /* @__PURE__ */ react.default.createElement(require_index.default, require_objectSpread2._objectSpread2({
			onChange: _onChange,
			value: valueString,
			onEnter: (e) => {
				onEnter(e);
			},
			rightPanel: /* @__PURE__ */ react.default.createElement(require_index$1.default, {
				value: previewValueString,
				onChange: onEnter,
				slice
			})
		}, timeProps)),
		open,
		placement: "bottom",
		arrow: false,
		onOpenChange,
		trigger: ["click"]
	}, popoverProps), /* @__PURE__ */ react.default.createElement(antd.TimePicker, require_objectSpread2._objectSpread2({
		format: "HH:mm",
		size: "large",
		inputReadOnly: true,
		allowClear: false,
		open: false,
		value: timePickerValue
	}, timePickerProps))));
};
//#endregion
exports.default = SelectTime;
