const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
//#region src/components/productCard/components/MultiDay/utils.ts
function formatDateRanges(list) {
	const result = [];
	let currentGroup = null;
	list.forEach((item, index) => {
		const currentStartDate = (0, dayjs.default)(item.start_date);
		const currentEndDate = (0, dayjs.default)(item.end_date);
		const currentTotal = item.total;
		const currentNum = item.num;
		if (!currentGroup) currentGroup = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
			start_date: currentStartDate.format("YYYY-MM-DD"),
			end_date: currentEndDate.format("YYYY-MM-DD"),
			total: currentTotal,
			num: currentNum
		});
		else {
			const prevEndDate = (0, dayjs.default)(currentGroup.end_date);
			if (currentTotal === currentGroup.total && prevEndDate.isSame(currentStartDate, "day")) {
				currentGroup.end_date = currentEndDate.format("YYYY-MM-DD");
				currentGroup.num += currentNum;
			} else {
				result.push(currentGroup);
				currentGroup = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
					start_date: currentStartDate.format("YYYY-MM-DD"),
					end_date: currentEndDate.format("YYYY-MM-DD"),
					total: currentTotal,
					num: currentNum
				});
			}
		}
		if (index === list.length - 1 && currentGroup) result.push(currentGroup);
	});
	return result;
}
//#endregion
exports.formatDateRanges = formatDateRanges;
