//#region src/components/wallet/utils.ts
function formatDateTime(dateTime, isAll = false, locale = "zh-CN") {
	const date = new Date(dateTime);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, "0");
	const day = String(date.getDate()).padStart(2, "0");
	const hours = date.getHours();
	const minutes = String(date.getMinutes()).padStart(2, "0");
	if (isAll) if (locale === "en") return `${day}/${month}/${year}`;
	else return `${year}-${month}-${day}`;
	if (locale === "en") {
		const period = hours >= 12 ? "PM" : "AM";
		return `${day}/${month}/${year} ${hours === 0 ? 12 : hours > 12 ? hours - 12 : hours}:${minutes} ${period}`;
	} else return `${year}-${month}-${day} ${String(hours).padStart(2, "0")}:${minutes}`;
}
const textConfig = {
	"zh-HK": {
		weekdays: [
			"日",
			"一",
			"二",
			"三",
			"四",
			"五",
			"六"
		],
		separator: "、",
		timeSeparator: "–",
		rangeSeparator: " 至 ",
		periodSeparator: "；",
		timeSlotSeparator: "，",
		every: "每",
		day: "天",
		week: "周",
		month: "月",
		year: "年",
		available: "可用",
		unlimited: "无限期",
		weekPrefix: "周"
	},
	"zh-CN": {
		weekdays: [
			"日",
			"一",
			"二",
			"三",
			"四",
			"五",
			"六"
		],
		separator: "、",
		timeSeparator: "–",
		rangeSeparator: " 至 ",
		periodSeparator: "；",
		timeSlotSeparator: "，",
		every: "每",
		day: "天",
		week: "周",
		month: "月",
		year: "年",
		available: "可用",
		unlimited: "无限期",
		weekPrefix: "周"
	},
	"en": {
		weekdays: [
			"Sun",
			"Mon",
			"Tue",
			"Wed",
			"Thu",
			"Fri",
			"Sat"
		],
		separator: ", ",
		timeSeparator: "–",
		rangeSeparator: " - ",
		periodSeparator: "; ",
		timeSlotSeparator: ", ",
		every: "every ",
		day: "day",
		week: "week",
		month: "month",
		year: "year",
		available: "available",
		unlimited: "unlimited",
		weekPrefix: ""
	}
};
function getWeekdayText(dayNumbers, locale) {
	const config = textConfig[locale];
	return dayNumbers.map((day) => config.weekdays[day]).join(config.separator);
}
function getRepeatFrequencyText(repeatType, frequency, locale) {
	const config = textConfig[locale];
	const typeMap = {
		"daily": config.day,
		"weekly": config.week,
		"monthly": config.month,
		"yearly": config.year
	};
	if (locale === "en") {
		if (frequency === 1) return `${config.every}${typeMap[repeatType]}`;
		return `${config.every}${frequency} ${typeMap[repeatType]}s`;
	} else {
		if (frequency === 1) return `${config.every}${typeMap[repeatType]}`;
		return `${config.every}${frequency}${typeMap[repeatType]}`;
	}
}
/**
* 根据scheduleList格式化文案展示
* @param scheduleList 日程列表
* @returns 格式化后的文案结果数组，每个日程对应一个结果
*/
function formatScheduleText(scheduleList, locale = "en") {
	const results = [];
	const config = textConfig[locale];
	scheduleList.forEach((schedule) => {
		var _schedule$repeat_rule, _schedule$repeat_rule2;
		const validityTexts = [];
		const excluded_date = [];
		const included_date = [];
		if ((_schedule$repeat_rule = schedule.repeat_rule) === null || _schedule$repeat_rule === void 0 ? void 0 : _schedule$repeat_rule.excluded_date) schedule.repeat_rule.excluded_date.forEach((excludeItem) => {
			const startDate = formatDateTime(excludeItem.start, true, locale);
			const endDate = formatDateTime(excludeItem.end, true, locale);
			if (excludeItem.start === excludeItem.end) excluded_date.push(startDate);
			else excluded_date.push(`${startDate}${config.rangeSeparator}${endDate}`);
		});
		if ((_schedule$repeat_rule2 = schedule.repeat_rule) === null || _schedule$repeat_rule2 === void 0 ? void 0 : _schedule$repeat_rule2.included_date) schedule.repeat_rule.included_date.forEach((includeItem) => {
			const startDate = formatDateTime(includeItem.start, true, locale);
			const endDate = formatDateTime(includeItem.end, true, locale);
			if (includeItem.start === includeItem.end) included_date.push(startDate);
			else included_date.push(`${startDate}${config.rangeSeparator}${endDate}`);
		});
		const isAllDay = schedule.is_all === 1;
		let validityText = "";
		if (schedule.repeat_type === "none") {
			if (schedule.type === "standard") {
				const startDateTime = formatDateTime(schedule.start_time, isAllDay, locale);
				const endDateTime = formatDateTime(schedule.end_time, isAllDay, locale);
				validityText = `${startDateTime}${config.rangeSeparator}${endDateTime}`;
			} else if (schedule.type === "time-slots" && schedule.time_slot.length > 0) {
				const baseDate = formatDateTime(schedule.start_time, true, locale);
				if (isAllDay) validityText = `${baseDate}`;
				else validityText = `${baseDate} ${schedule.time_slot.map((slot) => `${slot.start_time}${config.timeSeparator}${slot.end_time}`).join(config.timeSlotSeparator)}`;
			} else if (schedule.type === "designation" && schedule.designation) {
				const designationTexts = schedule.designation.map((item) => {
					if (isAllDay || item.start_time === "00:00" && item.end_time === "23:59") {
						const startDate = formatDateTime(item.start_date, true, locale);
						const endDate = formatDateTime(item.end_date, true, locale);
						return `${startDate}${config.rangeSeparator}${endDate}`;
					} else return `${formatDateTime(item.start_date, true, locale)} ${item.start_time}${config.timeSeparator}${item.end_time}`;
				});
				validityTexts.push(...designationTexts);
			}
		} else if (schedule.repeat_rule) {
			const { frequency, frequency_date } = schedule.repeat_rule;
			const startText = isAllDay ? formatDateTime(schedule.start_time, true, locale) : formatDateTime(schedule.start_time, false, locale);
			let endDateText = "";
			if (schedule.repeat_rule.end.type === "never") endDateText = config.unlimited;
			else if (schedule.repeat_rule.end.end_date) endDateText = formatDateTime(schedule.repeat_rule.end.end_date, true, locale);
			if (schedule.type === "standard") {
				if (schedule.repeat_type === "daily") if (isAllDay) {
					const frequencyText = getRepeatFrequencyText("daily", frequency, locale);
					if (locale === "en") validityText = `${startText}${config.rangeSeparator}${endDateText}, ${config.available} ${frequencyText}`;
					else validityText = `${startText}${config.rangeSeparator}${endDateText}，${frequencyText}${config.available}`;
				} else {
					const startTime = formatDateTime(schedule.start_time, false, locale);
					const endTime = formatDateTime(schedule.end_time, false, locale);
					const timeRange = locale === "en" ? `${startTime.split(" ")[1]} ${startTime.split(" ")[2]}${config.timeSeparator}${endTime.split(" ")[1]} ${endTime.split(" ")[2]}` : `${startTime.split(" ")[1]}${config.timeSeparator}${endTime.split(" ")[1]}`;
					const frequencyText = getRepeatFrequencyText("daily", frequency, locale);
					const dateRange = locale === "en" ? `${startTime.split(" ")[0]}${config.rangeSeparator}${endDateText}` : `${startText.split(" ")[0]}${config.rangeSeparator}${endDateText}`;
					if (locale === "en") validityText = `${dateRange}, ${config.available} ${frequencyText} ${timeRange}`;
					else validityText = `${dateRange}，${frequencyText} ${timeRange} ${config.available}`;
				}
				else if (schedule.repeat_type === "weekly") {
					const weekdaysText = getWeekdayText(frequency_date, locale);
					if (isAllDay) if (locale === "en") {
						const frequencyText = frequency === 1 ? "every week" : `every ${frequency} weeks`;
						validityText = `${startText}${config.rangeSeparator}${endDateText}, ${frequencyText} on ${weekdaysText} `;
					} else {
						const frequencyText = frequency === 1 ? "每周" : `每${frequency}周的`;
						validityText = `${startText}${config.rangeSeparator}${endDateText}，${frequencyText}${config.weekPrefix}${weekdaysText}${config.available}`;
					}
					else {
						const startTime = formatDateTime(schedule.start_time, false, locale);
						const endTime = formatDateTime(schedule.end_time, false, locale);
						const timeRange = locale === "en" ? `${startTime.split(" ")[1]} ${startTime.split(" ")[2]}${config.timeSeparator}${endTime.split(" ")[1]} ${endTime.split(" ")[2]}` : `${startTime.split(" ")[1]}${config.timeSeparator}${endTime.split(" ")[1]}`;
						const dateRange = locale === "en" ? `${startTime.split(" ")[0]}${config.rangeSeparator}${endDateText}` : `${startText.split(" ")[0]}${config.rangeSeparator}${endDateText}`;
						if (locale === "en") validityText = `${dateRange}, ${frequency === 1 ? "every week" : `every ${frequency} weeks`} on ${weekdaysText} ${timeRange}`;
						else validityText = `${dateRange}，${frequency === 1 ? "每周" : `每${frequency}周的`}${config.weekPrefix}${weekdaysText} ${timeRange}`;
					}
				}
			} else if (schedule.type === "time-slots" && schedule.time_slot.length > 0) {
				const baseDate = formatDateTime(schedule.start_time, true, locale);
				const timeSlotsText = schedule.time_slot.map((slot) => `${slot.start_time}${config.timeSeparator}${slot.end_time}`).join(config.timeSlotSeparator);
				if (schedule.repeat_type === "daily") {
					const frequencyText = getRepeatFrequencyText("daily", frequency, locale);
					if (locale === "en") validityText = `${baseDate}${config.rangeSeparator}${endDateText}, ${config.available} ${frequencyText} ${timeSlotsText}`;
					else validityText = `${baseDate}${config.rangeSeparator}${endDateText}，${frequencyText} ${timeSlotsText} ${config.available}`;
				} else if (schedule.repeat_type === "weekly") {
					const weekdaysText = getWeekdayText(frequency_date, locale);
					if (locale === "en") {
						const frequencyText = frequency === 1 ? "every week" : `every ${frequency} weeks`;
						validityText = `${baseDate}${config.rangeSeparator}${endDateText}, ${frequencyText} on ${weekdaysText} ${timeSlotsText}`;
					} else {
						const frequencyText = frequency === 1 ? "每周" : `每${frequency}周的`;
						validityText = `${baseDate}${config.rangeSeparator}${endDateText}，${frequencyText}${config.weekPrefix}${weekdaysText} ${timeSlotsText} ${config.available}`;
					}
				}
			}
		} else if (schedule.type === "designation" && schedule.designation) {
			const designationTexts = schedule.designation.map((item) => {
				if (isAllDay || item.start_time === "00:00" && item.end_time === "23:59") {
					const startDate = formatDateTime(item.start_date, true, locale);
					const endDate = formatDateTime(item.end_date, true, locale);
					return `${startDate}${config.rangeSeparator}${endDate}`;
				} else return `${formatDateTime(item.start_date, true, locale)} ${item.start_time}${config.timeSeparator}${item.end_time}`;
			});
			validityTexts.push(...designationTexts);
		}
		if (validityText) validityTexts.push(validityText);
		results.push({
			validityTexts,
			excluded_date,
			included_date
		});
	});
	return results;
}
//#endregion
exports.formatScheduleText = formatScheduleText;
