/** Seasonal factor chart renderers. */ import { html, svg, nothing } from "lit"; import { t } from "../styles"; import type { MaintenanceTask, AdvancedFeatures } from "../types"; const MONTH_KEYS = [ "month_jan", "month_feb", "month_mar", "month_apr", "month_may", "month_jun", "month_jul", "month_aug", "month_sep", "month_oct", "month_nov", "month_dec", ]; export function renderSeasonalCardCompact(task: MaintenanceTask, lang: string, features: AdvancedFeatures) { if (!features.seasonal || !task.seasonal_factor || task.seasonal_factor === 1.0) { return nothing; } const months = MONTH_KEYS.map(k => t(k, lang)); const currentMonth = new Date().getMonth(); const realFactors = task.seasonal_factors || task.interval_analysis?.seasonal_factors || null; const seasonalData = realFactors && realFactors.length === 12 ? realFactors : months.map((_, i) => { const base = task.seasonal_factor || 1.0; const variation = Math.sin((i - 6) * Math.PI / 6) * 0.3; return Math.max(0.7, Math.min(1.3, base + variation)); }); return html`

${t("seasonal_awareness", lang)}

${seasonalData.map((factor, i) => { const height = factor * 40; const colorClass = factor < 0.9 ? 'low' : factor > 1.1 ? 'high' : 'normal'; const isCurrentMonth = i === currentMonth; return html`
`; })}
${t("shorter", lang) || "Kürzer"} ${t("normal", lang) || "Normal"} ${t("longer", lang) || "Länger"}
`; } export function renderSeasonalCardExpanded(task: MaintenanceTask, lang: string) { return renderSeasonalChart(task, lang); } // Module-private — only the `renderSeasonalCardExpanded` wrapper above is part // of the renderers/ public surface. Drop the keyword so esbuild sees the // symbol as internal and tree-shakes it cleanly when the wrapper changes. function renderSeasonalChart(task: MaintenanceTask, lang: string) { const factors = task.seasonal_factors ?? task.interval_analysis?.seasonal_factors; if (!factors || factors.length !== 12) return nothing; const reason = task.interval_analysis?.seasonal_reason; const currentMonth = new Date().getMonth(); const W = 300, H = 100; const PAD_T = 8, PAD_B = 4; const chartH = H - PAD_T - PAD_B; const maxFactor = Math.max(...factors, 1.5); const barW = W / 12; const barInner = barW * 0.65; const baselineY = PAD_T + chartH - (1.0 / maxFactor) * chartH; return html`
${t("seasonal_chart_title", lang)} ${reason ? html`${reason === "learned" ? t("seasonal_learned", lang) : t("seasonal_manual", lang)}` : nothing}
${factors.map((f, i) => { const barH = (f / maxFactor) * chartH; const x = i * barW + (barW - barInner) / 2; const y = PAD_T + chartH - barH; const isCurrent = i === currentMonth; const color = f < 1.0 ? "var(--success-color, #4caf50)" : f > 1.0 ? "var(--warning-color, #ff9800)" : "var(--secondary-text-color)"; return svg` `; })}
${MONTH_KEYS.map((key, i) => html`${t(key, lang)}` )}
`; }