import { useState } from 'react'; import type { WeatherSnapshot } from '../../entities/weather/model/types'; import { getWindDirectionLabel, getWindArrow, getWaveSeverity, getWeatherLabel, } from '../../entities/weather/lib/weatherUtils'; interface WeatherPanelProps { snapshot: WeatherSnapshot | null; isLoading: boolean; error: string | null; onRefresh: () => void; } function fmtTime(ts: number): string { const d = new Date(ts); return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`; } function fmtVal(v: number | null, unit: string, decimals = 1): string { if (v == null) return '-'; return `${v.toFixed(decimals)}${unit}`; } export function WeatherPanel({ snapshot, isLoading, error, onRefresh }: WeatherPanelProps) { const [open, setOpen] = useState(false); return ( <> {open && (
해양 기상 현황 {isLoading && 조회중...}
{error &&
{error}
} {snapshot && snapshot.points.map((pt) => { const severity = getWaveSeverity(pt.waveHeight); const isWarn = severity === 'rough' || severity === 'severe' || (pt.windSpeed != null && pt.windSpeed >= 10); return (
{pt.label}
~ {fmtVal(pt.waveHeight, 'm')} {getWindArrow(pt.windDirection)} {fmtVal(pt.windSpeed, 'm/s')} {getWindDirectionLabel(pt.windDirection)}
수온 {fmtVal(pt.seaSurfaceTemp, '°C')} 너울 {fmtVal(pt.swellHeight, 'm')} {pt.weatherCode != null && ( {getWeatherLabel(pt.weatherCode)} )}
); })} {!snapshot && !isLoading && !error && (
데이터 없음
)}
{snapshot && ( 갱신 {fmtTime(snapshot.fetchedAt)} )}
)} ); }