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_localeUtils = require("./utils/localeUtils.js");
const require_useCurrentTime = require("./hooks/useCurrentTime.js");
const require_relativeDay = require("./utils/relativeDay.js");
const require_getRefreshInterval = require("./utils/getRefreshInterval.js");
const require_TimeDisplay = require("./components/TimeDisplay.js");
const require_DateDisplay = require("./components/DateDisplay.js");
const require_WeekdayDisplay = require("./components/WeekdayDisplay.js");
const require_dateTimeDisplayFormats = require("./formats/dateTimeDisplayFormats.js");
let react = require("react");
react = require_runtime.__toESM(react);
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
require("dayjs/locale/zh-cn");
require("dayjs/locale/en");
require("./PisellDateTimeDisplay.less");
//#region src/components/pisellDateTimeDisplay/PisellDateTimeDisplay.tsx
/**
* PisellDateTimeDisplay 组件
*
* @description
* 专注于展示当前时间的组件，支持：
* - 当前日期、时间、星期展示
* - 多种布局方式（水平、垂直、单行）
* - 丰富的格式化配置
* - 自动刷新
* - 国际化支持
*
* @example
* // 基础用法
* <PisellDateTimeDisplay />
*
* // 自定义格式
* <PisellDateTimeDisplay
*   layout="vertical"
*   timeFormat={{ use12Hour: true, showSeconds: true }}
*   dateFormat={{ showYear: true, showChineseUnit: true }}
* />
*
* // 自定义格式化字符串
* <PisellDateTimeDisplay
*   customFormat="YYYY-MM-DD HH:mm:ss"
* />
*/
const PisellDateTimeDisplay = (props) => {
	var _context$engine, _ref, _presetSource$localeK;
	const { value: valueProp, layout = "horizontal", textAlign = "center", fields, formatByLocale, timeFormat, dateFormat, weekdayFormat, customFormat, inlineSeparator = " · ", containerStyle, timeStyle, dateStyle, weekdayStyle, refreshInterval, disableAutoRefresh = false, locale, onTimeUpdate, onClick, className, style } = props;
	const context = require_useEngineContext.default();
	const resolvedLocale = locale || (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 localeKey = require_localeUtils.getDayjsLocale(resolvedLocale);
	const baseLocale = localeKey.split("-")[0];
	const presetSource = formatByLocale !== null && formatByLocale !== void 0 ? formatByLocale : require_dateTimeDisplayFormats.DATETIME_DISPLAY_FORMATS;
	const preset = (_ref = (_presetSource$localeK = presetSource[localeKey]) !== null && _presetSource$localeK !== void 0 ? _presetSource$localeK : presetSource[baseLocale]) !== null && _ref !== void 0 ? _ref : {};
	const effectiveFields = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, preset.fields), fields);
	const effectiveDateFormat = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, preset.dateFormat), dateFormat);
	const effectiveTimeFormat = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, preset.timeFormat), timeFormat);
	const effectiveWeekdayFormat = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, preset.weekdayFormat), weekdayFormat);
	const currentTime = require_useCurrentTime.useCurrentTime({
		refreshInterval: refreshInterval !== null && refreshInterval !== void 0 ? refreshInterval : require_getRefreshInterval.getRefreshInterval(effectiveTimeFormat),
		disabled: disableAutoRefresh || valueProp !== void 0,
		locale: resolvedLocale,
		onUpdate: onTimeUpdate
	});
	const displayTime = valueProp !== void 0 && valueProp !== null ? (0, dayjs.default)(valueProp).locale(localeKey) : currentTime;
	if (customFormat) {
		const formattedTime = displayTime.format(customFormat);
		const containerInlineStyle = require_objectSpread2._objectSpread2({
			background: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.background,
			borderRadius: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.borderRadius,
			border: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.border,
			boxShadow: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.boxShadow,
			padding: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.padding,
			textAlign
		}, style);
		return /* @__PURE__ */ react.default.createElement("div", {
			className: `pisell-datetime-display pisell-datetime-display-custom ${className || ""}`.trim(),
			style: containerInlineStyle,
			onClick
		}, /* @__PURE__ */ react.default.createElement("span", null, formattedTime));
	}
	const { showTime = true, showDate = true, showWeekday = true, fieldOrder = [
		"time",
		"date",
		"weekday"
	] } = effectiveFields || {};
	const referenceDate = (0, dayjs.default)();
	const relativeDay = (effectiveDateFormat === null || effectiveDateFormat === void 0 ? void 0 : effectiveDateFormat.showRelativeDay) ? require_relativeDay.getRelativeDay(displayTime, referenceDate) : null;
	const hideWeekdayWhenDateRelative = showDate && relativeDay !== null;
	const containerInlineStyle = require_objectSpread2._objectSpread2({
		background: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.background,
		borderRadius: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.borderRadius,
		border: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.border,
		boxShadow: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.boxShadow,
		padding: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.padding,
		gap: containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.gap,
		textAlign
	}, style);
	const renderField = (fieldType) => {
		switch (fieldType) {
			case "time": return showTime ? /* @__PURE__ */ react.default.createElement(require_TimeDisplay.default, {
				key: "time",
				time: displayTime,
				format: effectiveTimeFormat,
				style: timeStyle
			}) : null;
			case "date": return showDate ? /* @__PURE__ */ react.default.createElement(require_DateDisplay.default, {
				key: "date",
				date: displayTime,
				format: effectiveDateFormat,
				referenceDate: (0, dayjs.default)(),
				style: dateStyle
			}) : null;
			case "weekday": return showWeekday && !hideWeekdayWhenDateRelative ? /* @__PURE__ */ react.default.createElement(require_WeekdayDisplay.default, {
				key: "weekday",
				weekday: displayTime,
				format: effectiveWeekdayFormat,
				style: weekdayStyle
			}) : null;
			default: return null;
		}
	};
	if (layout === "inline") {
		const inlineSeparators = effectiveFields === null || effectiveFields === void 0 ? void 0 : effectiveFields.inlineSeparators;
		const renderedFields = fieldOrder.map(renderField).filter((field) => field !== null);
		if (renderedFields.length === 0) return null;
		return /* @__PURE__ */ react.default.createElement("div", {
			className: `pisell-datetime-display pisell-datetime-display-inline ${className || ""}`.trim(),
			style: containerInlineStyle,
			onClick
		}, renderedFields.map((field, index) => {
			var _inlineSeparators$ind;
			return /* @__PURE__ */ react.default.createElement(react.default.Fragment, { key: index }, field, index < renderedFields.length - 1 && /* @__PURE__ */ react.default.createElement("span", { className: "pisell-datetime-display-separator" }, (_inlineSeparators$ind = inlineSeparators === null || inlineSeparators === void 0 ? void 0 : inlineSeparators[index]) !== null && _inlineSeparators$ind !== void 0 ? _inlineSeparators$ind : inlineSeparator));
		}));
	}
	const renderedFields = fieldOrder.map(renderField).filter((field) => field !== null);
	if (renderedFields.length === 0) return null;
	if (layout === "horizontal") {
		const timeField = showTime ? renderField("time") : null;
		const isChinese$1 = require_localeUtils.isChinese(displayTime.locale());
		if (showDate && showWeekday) {
			var _labels$relativeDay;
			const labels = effectiveDateFormat === null || effectiveDateFormat === void 0 ? void 0 : effectiveDateFormat.relativeDayLabels;
			const dateStr = relativeDay ? (_labels$relativeDay = labels === null || labels === void 0 ? void 0 : labels[relativeDay]) !== null && _labels$relativeDay !== void 0 ? _labels$relativeDay : require_relativeDay.getRelativeDayLabel(relativeDay, displayTime.locale()) : isChinese$1 ? displayTime.format("M月D日") : displayTime.format("D MMM");
			const weekdayStr = displayTime.format("ddd");
			const combinedStr = relativeDay ? dateStr : isChinese$1 ? `${weekdayStr} ${dateStr}` : `${weekdayStr}, ${dateStr}`;
			const dateInlineStyle = {
				fontSize: dateStyle === null || dateStyle === void 0 ? void 0 : dateStyle.fontSize,
				fontWeight: dateStyle === null || dateStyle === void 0 ? void 0 : dateStyle.fontWeight,
				color: dateStyle === null || dateStyle === void 0 ? void 0 : dateStyle.color,
				lineHeight: dateStyle === null || dateStyle === void 0 ? void 0 : dateStyle.lineHeight
			};
			return /* @__PURE__ */ react.default.createElement("div", {
				className: `pisell-datetime-display pisell-datetime-display-${layout} ${className || ""}`.trim(),
				style: containerInlineStyle,
				onClick
			}, timeField, /* @__PURE__ */ react.default.createElement("span", {
				className: "pisell-datetime-display-date pisell-datetime-display-combined",
				style: dateInlineStyle
			}, combinedStr));
		}
		const dateField = showDate ? renderField("date") : null;
		const weekdayField = showWeekday ? renderField("weekday") : null;
		return /* @__PURE__ */ react.default.createElement("div", {
			className: `pisell-datetime-display pisell-datetime-display-${layout} ${className || ""}`.trim(),
			style: containerInlineStyle,
			onClick
		}, timeField, (dateField || weekdayField) && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-datetime-display-date-weekday-row" }, dateField, weekdayField));
	}
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `pisell-datetime-display pisell-datetime-display-${layout} ${className || ""}`.trim(),
		style: containerInlineStyle,
		onClick
	}, renderedFields);
};
var PisellDateTimeDisplay_default = react.default.memo(PisellDateTimeDisplay);
//#endregion
exports.default = PisellDateTimeDisplay_default;
