import { useEffect } from 'preact/hooks' import { HG, hgColor, type HgCat } from '../categories' import { lang, t, tKey } from '../i18n' import { mapBoxMM } from '../page' import { commentary, mapAuthor, mapTitle, orientation, printJob } from '../state' import { frameStats } from '../stats' /** Short legend label: "Ostatní plochy" under its group heading, like the assignment's legend. */ const legendLabel = (k: string) => { const s = tKey('hgs.' + k) return s.startsWith('hgs.') ? tKey('hg.' + k) : s } /** * Pages for printing / "Save as PDF", shown only while a print job is prepared. * Submission: 1 map, 2 legend, 3–4 commentary. Worksheet: blank map and a legend to colour in. */ export function PrintView() { const job = printJob.value useEffect(() => { const done = () => { const j = printJob.value if (!j) return URL.revokeObjectURL(j.mapUrl) printJob.value = null } window.addEventListener('afterprint', done) return () => window.removeEventListener('afterprint', done) }, []) useEffect(() => { document.documentElement.classList.toggle('printing', !!job) }, [job]) if (!job) return null const ws = job.kind === 'worksheet', o = orientation.value, [wmm, hmm] = mapBoxMM(o) const title = mapTitle.value.trim() || t('title'), author = mapAuthor.value.trim() const date = new Date().toLocaleDateString(lang.value, { day: 'numeric', month: 'long', year: 'numeric', }) const st = frameStats.value // the legend lists only categories that occur in the frame (the worksheet lists all 16) const present = (c: HgCat) => ws || !st || (st.area[c.key] ?? 0) > 0 const group = (built: boolean) => HG.filter((c) => c.built === built && present(c)) return ( ) }