export interface Event {
    id: number;
    resourceId: number;
    title: string;
    serviceName?: string;
    start: Date;
    end: Date;
    laneIndex?: number;
    status?: 'PENDING' | 'CONFIRMED' | 'COMPLETED' | 'CANCELLED' | 'NO_SHOW';
    isPaid?: boolean;
}

export function calculateLayout(events: Event[]): Event[] {
    const sortedEvents = [...events].sort((a, b) => a.start.getTime() - b.start.getTime());
    const laneEndTimes: number[] = [];

    return sortedEvents.map((event) => {
        let laneIndex = 0;
        let placed = false;

        while (!placed) {
            const laneEndTime = laneEndTimes[laneIndex] || 0;
            if (laneEndTime <= event.start.getTime()) {
                laneEndTimes[laneIndex] = event.end.getTime();
                placed = true;
            } else {
                laneIndex++;
            }
        }

        return { ...event, laneIndex };
    });
}
