const require_localeUtils = require("./localeUtils.js");
//#region src/components/pisellDateTimeDisplay/utils/formatDate.ts
/**
* 格式化日期
* @param date dayjs 日期对象
* @param config 日期格式配置
* @returns 格式化后的日期字符串
*
* @example
* // 英文环境
* formatDate(dayjs(), { order: 'YMD', shortMonth: true, showYear: true })
* // => "2026-Mar-21"
*
* // 中文环境
* formatDate(dayjs(), { order: 'YMD', showChineseUnit: true, showYear: true })
* // => "2026年3月21日"
*
* formatDate(dayjs(), { order: 'MDY', shortMonth: false, showYear: true })
* // => "March 21, 2026"
*/
function formatDate(date, config) {
	const { order = "YMD", shortMonth = true, numericMonth = false, showChineseUnit = false, separator = "-", showYear = false, showMonth = true, showDay = true, useCommaBeforeYear = true } = config || {};
	const isChinese$1 = require_localeUtils.isChinese(date.locale());
	const parts = [];
	const yearFormat = isChinese$1 && showChineseUnit ? "YYYY年" : "YYYY";
	let monthFormat = "";
	if (numericMonth) monthFormat = isChinese$1 && showChineseUnit ? "M月" : "MM";
	else if (isChinese$1) monthFormat = showChineseUnit ? "M月" : "M";
	else monthFormat = shortMonth ? "MMM" : "MMMM";
	const dayFormat = isChinese$1 && showChineseUnit ? "D日" : "DD";
	switch (order) {
		case "YMD":
			if (showYear) parts.push(yearFormat);
			if (showMonth) parts.push(monthFormat);
			if (showDay) parts.push(dayFormat);
			break;
		case "MDY":
			if (showMonth) parts.push(monthFormat);
			if (showDay) parts.push(dayFormat);
			if (showYear) parts.push(yearFormat);
			break;
		case "DMY":
			if (showDay) parts.push(dayFormat);
			if (showMonth) parts.push(monthFormat);
			if (showYear) parts.push(yearFormat);
			break;
	}
	if (parts.length === 0) return "";
	if (isChinese$1 && showChineseUnit) return date.format(parts.join(""));
	if (order === "MDY" && !isChinese$1) {
		const formatted = date.format(parts.join(" "));
		if (showYear && showMonth && showDay) {
			const [month, day, year] = formatted.split(" ");
			return `${month} ${day}, ${year}`;
		}
		if (showYear && showDay && !showMonth) {
			const [day, year] = formatted.split(" ");
			return `${day}, ${year}`;
		}
		return formatted;
	}
	if (order === "DMY" && !isChinese$1) {
		const formatted = date.format(parts.join(" "));
		if (showYear && showMonth && showDay && useCommaBeforeYear) {
			const [day, month, year] = formatted.split(" ");
			return `${day} ${month}, ${year}`;
		}
		if (showYear && showDay && !showMonth && useCommaBeforeYear) {
			const [day, year] = formatted.split(" ");
			return `${day}, ${year}`;
		}
		return formatted;
	}
	return date.format(parts.join(separator));
}
//#endregion
exports.formatDate = formatDate;
