2025-09-12 00:36:02 +02:00
|
|
|
import { CalendarEvent } from '../types/CalendarTypes';
|
|
|
|
|
import { SwpAllDayEventElement } from '../elements/SwpEventElement';
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-13 00:39:56 +02:00
|
|
|
* AllDayEventRenderer - Simple rendering of all-day events
|
|
|
|
|
* Handles adding and removing all-day events from the header container
|
2025-09-12 00:36:02 +02:00
|
|
|
*/
|
|
|
|
|
export class AllDayEventRenderer {
|
2025-09-13 00:39:56 +02:00
|
|
|
private container: HTMLElement | null = null;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.getContainer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-13 20:47:42 +02:00
|
|
|
* Get or cache all-day container, create if it doesn't exist
|
2025-09-13 00:39:56 +02:00
|
|
|
*/
|
|
|
|
|
private getContainer(): HTMLElement | null {
|
|
|
|
|
if (!this.container) {
|
|
|
|
|
const header = document.querySelector('swp-calendar-header');
|
|
|
|
|
if (header) {
|
2025-09-13 20:47:42 +02:00
|
|
|
// Try to find existing container
|
2025-09-13 00:39:56 +02:00
|
|
|
this.container = header.querySelector('swp-allday-container');
|
2025-09-13 20:47:42 +02:00
|
|
|
|
|
|
|
|
// If not found, create it
|
|
|
|
|
if (!this.container) {
|
|
|
|
|
this.container = document.createElement('swp-allday-container');
|
|
|
|
|
header.appendChild(this.container);
|
2025-09-17 22:08:27 +02:00
|
|
|
|
|
|
|
|
// Create ghost columns for mouseenter events
|
|
|
|
|
this.createGhostColumns();
|
2025-09-13 20:47:42 +02:00
|
|
|
}
|
2025-09-13 00:39:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this.container;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-17 22:08:27 +02:00
|
|
|
/**
|
|
|
|
|
* Create ghost columns for mouseenter events
|
|
|
|
|
*/
|
|
|
|
|
private createGhostColumns(): void {
|
|
|
|
|
if (!this.container) return;
|
|
|
|
|
|
|
|
|
|
// Get all day headers to create matching ghost columns
|
|
|
|
|
const dayHeaders = document.querySelectorAll('swp-day-header');
|
|
|
|
|
dayHeaders.forEach((header, index) => {
|
|
|
|
|
const ghostColumn = document.createElement('swp-allday-column');
|
|
|
|
|
const headerElement = header as HTMLElement;
|
|
|
|
|
|
|
|
|
|
// Copy date from corresponding day header
|
|
|
|
|
if (headerElement.dataset.date) {
|
|
|
|
|
ghostColumn.dataset.date = headerElement.dataset.date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set grid column position (1-indexed)
|
|
|
|
|
ghostColumn.style.gridColumn = (index + 1).toString();
|
|
|
|
|
ghostColumn.style.gridRow = '1 / -1'; // Span all rows
|
|
|
|
|
|
|
|
|
|
this.container!.appendChild(ghostColumn);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-13 00:39:56 +02:00
|
|
|
/**
|
|
|
|
|
* Render an all-day event using factory pattern
|
|
|
|
|
*/
|
2025-09-18 00:05:54 +02:00
|
|
|
public renderAllDayEvent(event: CalendarEvent, targetDate?: string): HTMLElement | null {
|
2025-09-13 00:39:56 +02:00
|
|
|
const container = this.getContainer();
|
|
|
|
|
if (!container) return null;
|
|
|
|
|
|
|
|
|
|
const allDayElement = SwpAllDayEventElement.fromCalendarEvent(event, targetDate);
|
|
|
|
|
const element = allDayElement.getElement();
|
|
|
|
|
|
|
|
|
|
container.appendChild(element);
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove an all-day event by ID
|
|
|
|
|
*/
|
|
|
|
|
public removeAllDayEvent(eventId: string): void {
|
|
|
|
|
const container = this.getContainer();
|
|
|
|
|
if (!container) return;
|
|
|
|
|
|
|
|
|
|
const eventElement = container.querySelector(`swp-allday-event[data-event-id="${eventId}"]`);
|
|
|
|
|
if (eventElement) {
|
|
|
|
|
eventElement.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-12 00:36:02 +02:00
|
|
|
|
2025-09-13 00:39:56 +02:00
|
|
|
/**
|
|
|
|
|
* Clear cache when DOM changes
|
|
|
|
|
*/
|
|
|
|
|
public clearCache(): void {
|
|
|
|
|
this.container = null;
|
|
|
|
|
}
|
2025-09-12 00:36:02 +02:00
|
|
|
}
|