import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import dayjs from "dayjs";
//#region src/components/productCard/components/MultiDay/utils.ts
function formatDateRanges(list) {
	const result = [];
	let currentGroup = null;
	list.forEach((item, index) => {
		const currentStartDate = dayjs(item.start_date);
		const currentEndDate = dayjs(item.end_date);
		const currentTotal = item.total;
		const currentNum = item.num;
		if (!currentGroup) currentGroup = _objectSpread2(_objectSpread2({}, item), {}, {
			start_date: currentStartDate.format("YYYY-MM-DD"),
			end_date: currentEndDate.format("YYYY-MM-DD"),
			total: currentTotal,
			num: currentNum
		});
		else {
			const prevEndDate = dayjs(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 = _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
export { formatDateRanges };
