2026-11-02 18:34:04 -05:00
import { getCSS } from "../style/css" ;
import { TIMEZONE_CONFIG } from "../time/zones" ;
import { getWeekBounds , getAdjacentWeeks } from "../time/week" ;
import type { Preferences , TimezoneKey } from "../types" ;
2026-11-02 18:42:50 -05:00
import { escapeHtml } from "./utils" ;
2026-11-02 18:34:04 -05:00
export function renderPage ( title : string , bodyContent : string , prefs : Preferences ) : string {
const css = getCSS ( ) ;
const weekBounds = getWeekBounds ( prefs . week , prefs . tz ) ;
const { prev , next } = getAdjacentWeeks ( prefs . week ) ;
const tzLinks = ( Object . entries ( TIMEZONE_CONFIG ) as [ TimezoneKey , { iana : string ; label : string } ] [ ] )
. map ( ( [ key , config ] ) = > {
const isCurrent = key === prefs . tz ;
const href = buildLink ( "/week" , { . . . prefs , tz : key } ) ;
return ` <a href=" ${ href } " class="tz-link ${ isCurrent ? " tz-link--active" : "" } " ${ isCurrent ? ' aria-current="true"' : "" } > ${ config . label } </a> ` ;
} )
. join ( " · " ) ;
2026-11-02 19:15:49 -05:00
2026-11-02 18:34:04 -05:00
const themeLinks = [
{ key : "light" , label : "☀️ Light" } ,
{ key : "dark" , label : "🌙 Dark" } ,
{ key : "system" , label : "⚙️ System" } ,
]
. map ( ( { key , label } ) = > {
const isCurrent = key === prefs . theme ;
const href = buildLink ( "/week" , { . . . prefs , theme : key } ) ;
return ` <a href=" ${ href } " class="theme-link ${ isCurrent ? " theme-link--active" : "" } " ${ isCurrent ? ' aria-current="true"' : "" } > ${ label } </a> ` ;
} )
. join ( " · " ) ;
const prevLink = buildLink ( "/week" , { . . . prefs , week : prev } ) ;
const nextLink = buildLink ( "/week" , { . . . prefs , week : next } ) ;
return ` <!DOCTYPE html>
< html lang = "en" data-theme = "${prefs.theme}" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > $ { escapeHtml ( title ) } — VCR Calendar < / title >
< style > $ { css } < / style >
< / head >
< body >
< header class = "site-header" >
2026-11-02 18:42:50 -05:00
< h1 class = "site-title" > < a href = "/week" > 📻 VCR Calendar < / a > < / h1 >
2026-11-02 19:05:19 -05:00
< p class = "site-header__disclaimer" > Subject to change , not official < / p >
2026-11-02 18:34:04 -05:00
< nav class = "controls-bar" >
< div class = "controls-row" >
< a href = "${prevLink}" class = "week-nav" aria-label = "Previous week" > ← < / a >
< span class = "week-label" > $ { weekBounds . label } < / span >
< a href = "${nextLink}" class = "week-nav" aria-label = "Next week" > → < / a >
< / div >
< div class = "controls-row" > $ { tzLinks } < / div >
2026-11-02 19:15:49 -05:00
< div class = "controls-row" > $ { themeLinks } < / div >
< div class = "controls-row controls-row--reset" > < a href = "/week?reset=1" class = "reset-link" title = "Resets timezone, theme, and mode to defaults" > ↺ Reset < / a > < span class = "reset-hint" > resets all options < / span > < / div >
2026-11-02 18:34:04 -05:00
< / nav >
< / header >
2026-11-02 19:05:19 -05:00
< main class = "page-container" > $ { bodyContent } < / main >
2026-11-02 18:34:04 -05:00
< footer class = "site-footer" >
2026-11-02 18:42:50 -05:00
< p > Times shown in $ { escapeHtml ( TIMEZONE_CONFIG [ prefs . tz ] . label ) } < / p >
2026-11-02 18:34:04 -05:00
< p > voidzero Community Radio < / p >
< / footer >
< / body >
< / html > ` ;
}
function buildLink ( path : string , prefs : Record < string , string > ) : string {
const params = new URLSearchParams ( ) ;
2026-11-02 19:05:19 -05:00
if ( prefs . tz ) params . set ( "tz" , prefs . tz ) ;
if ( prefs . theme ) params . set ( "theme" , prefs . theme ) ;
if ( prefs . mode ) params . set ( "mode" , prefs . mode ) ;
2026-11-02 18:34:04 -05:00
if ( prefs . week ) params . set ( "week" , prefs . week ) ;
const qs = params . toString ( ) ;
return qs ? ` ${ path } ? ${ qs } ` : path ;
}