const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let _pisell_utils = require("@pisell/utils");
require("dayjs/locale/zh-cn");
require("dayjs/locale/en");
require("dayjs/locale/zh-tw");
require("dayjs/locale/ja");
require("dayjs/locale/pt");
//#region src/components/ticketBooking/utils/formatTime.ts
/**
* @title: 格式化服务的 开始时间-结束时间-时长, 用于展示
* @description:
* @param {any} item
* @param {any} currentDate
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-04-26 14:04
*/
const getServiceTime = (item, currentDate, utils) => {
	var _utils$storage, _item$format;
	if (!(0, dayjs.default)(currentDate).isValid()) return "";
	const locale = (item === null || item === void 0 ? void 0 : item.locale) || (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get("umi_locale")) || "en-US";
	const isEn = locale === "en-US" || locale === "en";
	dayjs.default.locale({
		"en-US": "en",
		"zh-CN": "zh-cn",
		"zh-HK": "zh-tw",
		"ja": "ja",
		"pt": "pt"
	}[locale]);
	let startDate = (0, dayjs.default)(item === null || item === void 0 ? void 0 : item.start_date);
	let endDate = (0, dayjs.default)(item === null || item === void 0 ? void 0 : item.end_date);
	let diffInDays = (item === null || item === void 0 ? void 0 : item.custom_day_count) || endDate.diff(startDate, "day");
	if (item === null || item === void 0 ? void 0 : item.duration_type) {
		const sameDay = startDate.isSame(endDate, "day");
		const dateFormat = isEn ? "DD/MM/YYYY" : "YYYY-MM-DD";
		const timeFormat = "HH:mm";
		const startTime = (item === null || item === void 0 ? void 0 : item.start_time) || startDate.format(timeFormat);
		const endTime = (item === null || item === void 0 ? void 0 : item.end_time) || endDate.format(timeFormat);
		let dateTime = "";
		if (sameDay) if (isEn) dateTime = `${startTime} ~ ${endTime} ${startDate.format(dateFormat)}`;
		else dateTime = `${startDate.format(dateFormat)} ${startTime} ~ ${endTime}`;
		else if (isEn) dateTime = `${startTime} ${startDate.format(dateFormat)} ~ ${endTime} ${endDate.format(dateFormat)}`;
		else dateTime = `${startDate.format(dateFormat)} ${startTime} ~ ${endDate.format(dateFormat)} ${endTime}`;
		const startDateTime = `${startDate.format("YYYY-MM-DD")} ${startTime}`;
		let _duration = (0, dayjs.default)(`${endDate.format("YYYY-MM-DD")} ${endTime}`).diff((0, dayjs.default)(startDateTime), item === null || item === void 0 ? void 0 : item.duration_type);
		let durationText = "";
		if ((item === null || item === void 0 ? void 0 : item.duration_type) === "minutes") {
			const hours = Math.floor(_duration / 60);
			const minutes = _duration % 60;
			durationText = _pisell_utils.locales.getText("pisell2.product.card.hour.minute")(hours, minutes);
		} else if ((item === null || item === void 0 ? void 0 : item.duration_type) === "days") durationText = _pisell_utils.locales.getText("pisell2.product.card.day")(_duration);
		else durationText = `${_duration}`;
		return `${dateTime} (${durationText})`;
	}
	let _format = isEn ? "ddd, DD/MM/YYYY" : "YYYY-MM-DD，ddd";
	if ((item === null || item === void 0 ? void 0 : item.hasOwnProperty("format")) && (item === null || item === void 0 || (_item$format = item.format) === null || _item$format === void 0 ? void 0 : _item$format.length) > 0) {
		var _item$format2, _item$format3;
		_format = isEn ? item === null || item === void 0 || (_item$format2 = item.format) === null || _item$format2 === void 0 ? void 0 : _item$format2[0] : item === null || item === void 0 || (_item$format3 = item.format) === null || _item$format3 === void 0 ? void 0 : _item$format3[1];
	}
	if (item === null || item === void 0 ? void 0 : item.show_time) {
		startDate = (0, dayjs.default)((item === null || item === void 0 ? void 0 : item.start_time) ? `${item === null || item === void 0 ? void 0 : item.start_date} ${item === null || item === void 0 ? void 0 : item.start_time}` : startDate.format("YYYY-MM-DD HH:mm"));
		endDate = (0, dayjs.default)((item === null || item === void 0 ? void 0 : item.end_time) ? `${item === null || item === void 0 ? void 0 : item.end_date} ${item === null || item === void 0 ? void 0 : item.end_time}` : endDate.format("YYYY-MM-DD HH:mm"));
	}
	if ((item === null || item === void 0 ? void 0 : item.duration_type) === "minutes") diffInDays = endDate.diff(startDate, "minute");
	const date = `${startDate.format(_format)} ~ ${endDate.format(_format)}`;
	let text = _pisell_utils.locales.getText("pisell2.product.card.day")(diffInDays);
	if (item === null || item === void 0 ? void 0 : item.custom_day_count) text = _pisell_utils.locales.getText("pisell2.product.card.day.event")(diffInDays);
	const textTypes = {
		"minutes": _pisell_utils.locales.getText("pisell2.product.card.minute")(diffInDays),
		"event": _pisell_utils.locales.getText("pisell2.product.card.day.event")(diffInDays)
	};
	text = (textTypes === null || textTypes === void 0 ? void 0 : textTypes[item === null || item === void 0 ? void 0 : item.duration_type]) || text;
	return `${date} (${`${diffInDays}${text}`})`;
};
//#endregion
exports.getServiceTime = getServiceTime;
