const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_usePisellConfig = require("../../pisell-config-provider/hooks/usePisellConfig.js");
const require_useEngineContext = require("../../../hooks/useEngineContext.js");
const require_localeUtils = require("../utils/localeUtils.js");
let react = require("react");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
//#region src/components/pisellDateTimeDisplay/hooks/useCurrentTime.ts
/**
* 管理当前时间状态的自定义 Hook
*
* @description
* - 自动创建定时器刷新时间
* - 支持自定义刷新间隔
* - 支持国际化（locale）：优先级为 用户指定 > 全局配置 > i18n 当前语言
* - 组件卸载时自动清除定时器
*
* @example
* const currentTime = useCurrentTime({
*   refreshInterval: 1000,
*   locale: 'zh-CN',
*   onUpdate: (time) => console.log(time.format())
* });
*
* @param options 配置项
* @returns 当前时间（Dayjs 对象）
*/
function useCurrentTime(options) {
	var _context$engine;
	const { refreshInterval = 6e4, disabled = false, locale: userLocale, onUpdate } = options || {};
	const globalConfig = require_usePisellConfig.default();
	const context = require_useEngineContext.default();
	const globalLocale = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.locale;
	const engineLocale = 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;
	const dayjsLocale = require_localeUtils.getDayjsLocale(userLocale || globalLocale || engineLocale || "en");
	const [currentTime, setCurrentTime] = (0, react.useState)(() => {
		return (0, dayjs.default)().locale(dayjsLocale);
	});
	(0, react.useEffect)(() => {
		if (disabled) return;
		const timer = setInterval(() => {
			const localizedTime = (0, dayjs.default)().locale(dayjsLocale);
			setCurrentTime(localizedTime);
			onUpdate === null || onUpdate === void 0 || onUpdate(localizedTime);
		}, refreshInterval);
		return () => {
			clearInterval(timer);
		};
	}, [
		refreshInterval,
		disabled,
		dayjsLocale,
		onUpdate
	]);
	(0, react.useEffect)(() => {
		setCurrentTime((prevTime) => prevTime.locale(dayjsLocale));
	}, [dayjsLocale]);
	return currentTime;
}
//#endregion
exports.useCurrentTime = useCurrentTime;
