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