"use client"; import { useState } from "react"; import { compass, dayName, formatClock, formatDuration, formatPrecip, formatShortDate, formatTemp, formatWind, tempValue, uvLabel, type Units, } from "@/lib/display"; import { pixelLabel } from "@/lib/styles"; import type { DailyForecast } from "@/lib/weather/types"; import { SkyIcon } from "../PixelArt"; /** * The daily forecast (up to 14 days) as rows: * * Today Oct 21 [icon] 60% 39° ━━━━━█████━━━━ 52° * * The bar shows each day's low→high against the whole period's range, * so warm and cold days stand out at a glance. Tap a row for its details. */ export function DailyView({ daily, units, timeZone, providerLabel, maxDaysOnPlan }: { daily: DailyForecast[]; units: Units; timeZone: string | null; providerLabel: string; maxDaysOnPlan: number; }) { const [openDay, setOpenDay] = useState(null); if (daily.length === 0) { return

Daily forecast unavailable for this location.

; } const periodLow = Math.min(...daily.map((d) => tempValue(d.lowC, units))); const periodHigh = Math.max(...daily.map((d) => tempValue(d.highC, units))); const span = Math.max(1, periodHigh - periodLow); const percentAlong = (celsius: number) => ((tempValue(celsius, units) - periodLow) / span) * 100; return (
    {daily.map((day) => { const isOpen = openDay === day.time; return (
  1. {isOpen && }
  2. ); })}
{daily.length < 14 && (

{providerLabel} gives {maxDaysOnPlan} days on this plan. Choose Open-Meteo for 14.

)}
); } function DayDetails({ day, units, timeZone }: { day: DailyForecast; units: Units; timeZone: string | null }) { const wind = day.windKph === null ? null : `${formatWind(day.windKph, units)}${day.windDeg !== null ? ` from ${compass(day.windDeg)}` : ""}${day.gustKph ? `, gusts ${formatWind(day.gustKph, units)}` : ""}`; const facts: [string, string | null][] = [ ["Precipitation", day.precipMm !== null ? `${formatPrecip(day.precipMm, units)}${day.precipChance !== null ? ` (${day.precipChance}% chance)` : ""}` : null], ["Wind", wind], ["UV index", day.uvIndexMax !== null ? `${Math.round(day.uvIndexMax)} ${uvLabel(day.uvIndexMax)}` : null], ["Humidity", day.humidity !== null ? `${Math.round(day.humidity)}%` : null], ["Sunrise", day.sunrise ? formatClock(day.sunrise, timeZone) : null], ["Sunset", day.sunset ? formatClock(day.sunset, timeZone) : null], ["Daylight", day.sunrise && day.sunset ? formatDuration(day.sunrise, day.sunset) : null], ]; return (
{day.summary &&

{day.summary}

}
{facts .filter(([, value]) => value !== null) .map(([label, value]) => (
{label}
{value}
))}
); }