import { RainType, Sky, type WeatherSlot } from '../api/client/types.gen' import { kst } from './lib' const RAIN_TEXT: Partial> = { [RainType.RAIN]: '비', [RainType.SLEET]: '진눈깨비', [RainType.SNOW]: '눈', [RainType.SHOWER]: '소나기' } const SKY_TEXT: Record = { [Sky.CLEAR]: '맑음', [Sky.PARTLY]: '구름 많음', [Sky.CLOUDY]: '흐림' } /** 칸 하나의 하늘 상태 한 마디: 비·눈이 오면 그걸, 아니면 하늘 */ export function skyText(slot: WeatherSlot) { return (slot.rain_type != null && RAIN_TEXT[slot.rain_type]) || (slot.sky != null ? SKY_TEXT[slot.sky] : slot.note) } /** 주어진 시(0~23)를 넘지 않는 마지막 칸 */ export function slotAt(slots: WeatherSlot[], hour: number) { let pick: WeatherSlot | undefined for (const s of slots) if (kst(s.at).h <= hour) pick = s return pick ?? slots[0] } export const deg = (v: number | null | undefined) => (v == null ? '?°' : `${Math.round(v)}°`)