2025-08-07 00:15:44 +02:00
|
|
|
// Header rendering strategy interface and implementations
|
|
|
|
|
|
2025-09-12 00:36:02 +02:00
|
|
|
import { CalendarConfig } from '../core/CalendarConfig';
|
2025-10-03 20:50:40 +02:00
|
|
|
import { DateService } from '../utils/DateService';
|
2025-08-07 00:15:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface for header rendering strategies
|
|
|
|
|
*/
|
2025-11-01 16:28:45 +01:00
|
|
|
export interface IHeaderRenderer {
|
2025-08-07 00:26:33 +02:00
|
|
|
render(calendarHeader: HTMLElement, context: HeaderRenderContext): void;
|
2025-08-24 23:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Context for header rendering
|
|
|
|
|
*/
|
|
|
|
|
export interface HeaderRenderContext {
|
|
|
|
|
currentWeek: Date;
|
|
|
|
|
config: CalendarConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Date-based header renderer (original functionality)
|
|
|
|
|
*/
|
2025-11-01 16:28:45 +01:00
|
|
|
export class DateHeaderRenderer implements IHeaderRenderer {
|
2025-10-03 20:50:40 +02:00
|
|
|
private dateService!: DateService;
|
2025-08-18 23:42:03 +02:00
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
render(calendarHeader: HTMLElement, context: HeaderRenderContext): void {
|
2025-08-25 22:05:57 +02:00
|
|
|
const { currentWeek, config } = context;
|
2025-10-09 23:08:33 +02:00
|
|
|
|
2025-09-25 20:39:48 +02:00
|
|
|
// FIRST: Always create all-day container as part of standard header structure
|
|
|
|
|
const allDayContainer = document.createElement('swp-allday-container');
|
|
|
|
|
calendarHeader.appendChild(allDayContainer);
|
2025-10-09 23:08:33 +02:00
|
|
|
|
|
|
|
|
// Initialize date service with timezone and locale from config
|
2025-11-01 16:28:45 +01:00
|
|
|
const timezone = config.getTimezone();
|
|
|
|
|
const locale = config.getLocale();
|
2025-10-30 23:47:30 +01:00
|
|
|
this.dateService = new DateService(config);
|
2025-10-09 23:08:33 +02:00
|
|
|
|
2025-10-03 20:50:40 +02:00
|
|
|
const workWeekSettings = config.getWorkWeekSettings();
|
|
|
|
|
const dates = this.dateService.getWorkWeekDates(currentWeek, workWeekSettings.workDays);
|
2025-08-20 21:38:54 +02:00
|
|
|
const weekDays = config.getDateViewSettings().weekDays;
|
2025-08-07 00:15:44 +02:00
|
|
|
const daysToShow = dates.slice(0, weekDays);
|
|
|
|
|
|
2025-08-18 22:27:17 +02:00
|
|
|
daysToShow.forEach((date, index) => {
|
2025-08-07 00:15:44 +02:00
|
|
|
const header = document.createElement('swp-day-header');
|
2025-10-03 20:50:40 +02:00
|
|
|
if (this.dateService.isSameDay(date, new Date())) {
|
2025-08-07 00:15:44 +02:00
|
|
|
(header as any).dataset.today = 'true';
|
|
|
|
|
}
|
2025-10-09 23:08:33 +02:00
|
|
|
|
|
|
|
|
const dayName = this.dateService.getDayName(date, 'long', locale).toUpperCase();
|
|
|
|
|
|
2025-08-07 00:15:44 +02:00
|
|
|
header.innerHTML = `
|
2025-08-20 00:39:31 +02:00
|
|
|
<swp-day-name>${dayName}</swp-day-name>
|
2025-08-07 00:15:44 +02:00
|
|
|
<swp-day-date>${date.getDate()}</swp-day-date>
|
|
|
|
|
`;
|
2025-10-03 20:50:40 +02:00
|
|
|
(header as any).dataset.date = this.dateService.formatISODate(date);
|
2025-10-09 23:08:33 +02:00
|
|
|
|
2025-08-07 00:26:33 +02:00
|
|
|
calendarHeader.appendChild(header);
|
2025-08-07 00:15:44 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|