import type Calendar from "./Calendar.js"; import DayPicker from "./DayPicker.js"; import MonthPicker from "./MonthPicker.js"; import YearPicker from "./YearPicker.js"; import YearRangePicker from "./YearRangePicker.js"; import CalendarHeaderTemplate from "./CalendarHeaderTemplate.js"; import CalendarSelectionMode from "./types/CalendarSelectionMode.js"; export default function CalendarTemplate(this: Calendar) { const showMultipleMonths = this._monthsToShow > 1 && !this._isDayPickerHidden; const shouldRenderSeparateHeaders = this._isDefaultHeaderModeInMultipleMonths && !this._portraitView && !this._isCompactMode; const shouldRenderInlineHeaders = this._isDefaultHeaderModeInMultipleMonths && (this._portraitView || this._isCompactMode); return ( <>
{!showMultipleMonths && (
{ CalendarHeaderTemplate.call(this) }
)}
{showMultipleMonths ? ( <> {/* When pickers are active, show standard calendar header */} {this._shouldShowOnePickerHeaderButtonInMultipleMonths && (
{ CalendarHeaderTemplate.call(this) }
)}
{/* Render headers in separate loop when in horizontal layout (cozy mode, not portrait, not compact) */} {shouldRenderSeparateHeaders && (
{renderMonthHeaders.call(this)}
)} {/* Render day pickers (with inline headers in vertical layout) */}
{renderMonthPickers.call(this, shouldRenderInlineHeaders)}
) : ( <>
{showMultipleMonths && (
{renderMonthPicker.call(this)} {renderYearPicker.call(this)} {renderYearRangePicker.call(this)}
)}
); } /** * Renders month headers in a separate loop (horizontal layout) */ function renderMonthHeaders(this: Calendar) { return Array.from({ length: this._monthsToShow }, (_, index) => { const monthTimestamp = this._getMonthTimestamp(index); const isFirst = index === 0; const isLast = index === this._monthsToShow - 1; return (
{CalendarHeaderTemplate.call(this, { headerText: this._getHeaderTextForMonth(monthTimestamp), isFirst, isLast, isMultiple: true, })}
); }); } /** * Renders month pickers (with optional inline headers for vertical layout) */ function renderMonthPickers(this: Calendar, shouldRenderInlineHeaders: boolean) { return Array.from({ length: this._monthsToShow }, (_, index) => { const monthTimestamp = this._getMonthTimestamp(index); const isFirst = index === 0; const isLast = index === this._monthsToShow - 1; return (
{/* Render header inline when in vertical layout (portrait OR compact) */} {shouldRenderInlineHeaders && CalendarHeaderTemplate.call(this, { headerText: this._getHeaderTextForMonth(monthTimestamp), isFirst, isLast, isMultiple: true, }) }
); }); } function renderMonthPicker(this: Calendar) { return (