const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
let _pisell_utils = require("@pisell/utils");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
require("dayjs/locale/zh-cn");
require("dayjs/locale/ja");
require("dayjs/locale/pt");
require("dayjs/locale/en");
require("dayjs/locale/zh-tw");
//#region src/components/productCard/utils.ts
/**
* @title: 是否英文
* @description: 
* @param {any} item
* @return {*}
* @Author: WangHan
* @Date: 2024-12-28 22:49
*/
const isEn = (item) => {
	const locale = (item === null || item === void 0 ? void 0 : item.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]);
	return _isEn;
};
/**
* @title: 跨日预约时间
* @description: 
* @param {any} item
* @return {*}
* @Author: WangHan
* @Date: 2024-12-28 22:50
*/
const formatMultiDayDate = (item) => {
	const _isEn = isEn(item);
	const startDate = (0, dayjs.default)(item === null || item === void 0 ? void 0 : item.start_date);
	const endDate = (0, dayjs.default)(item === null || item === void 0 ? void 0 : item.end_date);
	const _format = _isEn ? "ddd, DD/MM/YYYY" : "YYYY-MM-DD，ddd";
	return `${startDate.format(_format)} ~ ${endDate.format(_format)}`;
};
/**
* @title: 格式化服务的 开始时间-结束时间-时长, 用于展示
* @description:
* @param {any} item
* @param {any} currentDate
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-04-26 14:04
*/
const getServiceTime = (item, currentDate) => {
	var _utils$storage, _item$format;
	if (!(0, dayjs.default)(currentDate).isValid()) return "";
	const utils = require_useEngineContext.default().appHelper.utils || {};
	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";
	const durationType = (item === null || item === void 0 ? void 0 : item.duration_type) === "flexible" ? "minutes" : item === null || item === void 0 ? void 0 : item.duration_type;
	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 (durationType) {
		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}`;
			if (durationType === "days") dateTime = formatMultiDayDate({
				start_date: startDate.format("YYYY-MM-DD"),
				end_date: endDate.format("YYYY-MM-DD"),
				locale
			});
		}
		const startDateTime = `${startDate.format("YYYY-MM-DD")} ${startTime}`;
		let _duration = (0, dayjs.default)(`${endDate.format("YYYY-MM-DD")} ${endTime}`).diff((0, dayjs.default)(startDateTime), durationType);
		let durationText = "";
		if (durationType === "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 (durationType === "days") durationText = `${_duration}${_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 (durationType === "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[durationType]) || text;
	return `${date} (${`${diffInDays}${text}`})`;
};
//#endregion
exports.formatMultiDayDate = formatMultiDayDate;
exports.getServiceTime = getServiceTime;
