import { getEventDuration, getEventHour } from "./index57.js";
//#region src/components/molecules/data/Calendar/_shared/overlap.ts
/**
* Resolve overlapping events into non-overlapping columns.
* Uses a greedy column-assignment approach:
* 1. Sort events by start time
* 2. Group events into overlap clusters (connected components)
* 3. Within each cluster, assign columns greedily
*/
function resolveOverlaps(events) {
	if (events.length === 0) return [];
	const sorted = [...events].sort((a, b) => {
		const aStart = getEventHour(a.start);
		const bStart = getEventHour(b.start);
		if (aStart !== bStart) return aStart - bStart;
		return getEventDuration(b.start, b.end) - getEventDuration(a.start, a.end);
	});
	const clusters = [];
	let currentCluster = [sorted[0]];
	let clusterEnd = getEventHour(sorted[0].start) + getEventDuration(sorted[0].start, sorted[0].end);
	for (let i = 1; i < sorted.length; i++) {
		const eventStart = getEventHour(sorted[i].start);
		if (eventStart < clusterEnd) {
			currentCluster.push(sorted[i]);
			const thisEnd = eventStart + getEventDuration(sorted[i].start, sorted[i].end);
			clusterEnd = Math.max(clusterEnd, thisEnd);
		} else {
			clusters.push(currentCluster);
			currentCluster = [sorted[i]];
			clusterEnd = eventStart + getEventDuration(sorted[i].start, sorted[i].end);
		}
	}
	clusters.push(currentCluster);
	const result = [];
	for (const cluster of clusters) {
		const columns = [];
		const assignments = /* @__PURE__ */ new Map();
		for (const event of cluster) {
			const eventStart = getEventHour(event.start);
			let placed = false;
			for (let col = 0; col < columns.length; col++) if (eventStart >= columns[col].end) {
				columns[col].end = eventStart + getEventDuration(event.start, event.end);
				assignments.set(event.id, col);
				placed = true;
				break;
			}
			if (!placed) {
				assignments.set(event.id, columns.length);
				columns.push({ end: eventStart + getEventDuration(event.start, event.end) });
			}
		}
		const totalColumns = columns.length;
		for (const event of cluster) result.push({
			event,
			column: assignments.get(event.id) ?? 0,
			totalColumns
		});
	}
	return result;
}
//#endregion
export { resolveOverlaps };

//# sourceMappingURL=index61.js.map