import { useState } from 'react' import data from '../../seo/foliage_2026.json' import { cx } from '../lib/utils' import { kst } from './lib' import { PostFrame } from './Post' type Mountain = { name: string; region: string; lat: number; lon: number; peak: string } type Stage = 'peak' | 'soon' | 'before' | 'after' // 지도 그림(public/foliage/korea-map.webp, 정사각형)의 위경도 → 그림 위 위치. generated-images/foliage-map/south_outline.json 과 같은 값 const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62.92, size: 1024 } const PEAK_DAYS = 3 // 절정일 앞뒤 이만큼은 '지금 절정' const SOON_DAYS = 7 const SEASON = { from: '09-20', to: '11-25' } const SEOUL = { lat: 37.566, lon: 126.978 } const STAGE: Record = { peak: { label: '지금 절정', dot: 'bg-[#ff5a36]' }, soon: { label: '곧 절정', dot: 'bg-[#ffb02e]' }, before: { label: '아직', dot: 'bg-[#7cc47a]' }, after: { label: '절정 지남', dot: 'bg-[#b9a69a]' }, } const pos = (m: Mountain) => ({ left: `${((MAP.ox + (m.lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size) * 100}%`, top: `${((MAP.oy + (MAP.lat1 - m.lat) * MAP.s) / MAP.size) * 100}%`, }) // 점이 붙은 곳은 이름을 점 왼쪽·위·아래로 돌려 겹치지 않게. 없으면 오른쪽 type Side = 'left' | 'right' | 'top' | 'bottom' const SIDE: Record = { 광덕산: 'left', 설악산: 'top', 금원산: 'top', 두륜산: 'left', '한라산(1100도로)': 'left', } const LABEL_AT: Record = { right: 'left-full top-1/2 -translate-y-1/2', left: 'right-full top-1/2 -translate-y-1/2', top: 'bottom-full left-1/2 -translate-x-1/2', bottom: 'top-full left-1/2 -translate-x-1/2', } const short = (name: string) => name.replace(/\(.*\)$/, '') const DAY = 86_400_000 const days = (from: string, to: string) => Math.round((Date.parse(to) - Date.parse(from)) / DAY) function stage(m: Mountain, today: string): Stage { const d = days(today, m.peak) if (Math.abs(d) <= PEAK_DAYS) return 'peak' if (d < 0) return 'after' return d <= SOON_DAYS ? 'soon' : 'before' } const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}` /** 단풍철에만 나오는 단풍 지도 카드. 산마다 절정 예측일로 지금 절정·곧·아직·지남을 점으로 */ export function FoliageCard() { const [now] = useState(() => new Date()) const t = kst(now) const today = `${t.y}-${String(t.mo).padStart(2, '0')}-${String(t.d).padStart(2, '0')}` const [picked, setPicked] = useState(null) const mmdd = today.slice(5) if (mmdd < SEASON.from || mmdd > SEASON.to) return null const mountains = (data.mountains as unknown as Mountain[]).map((m) => ({ ...m, stage: stage(m, today) })) const peakNow = mountains.filter((m) => m.stage === 'peak').map((m) => m.name) // 발표 지도에 서울 안 산은 없어 서울 시청에서 가장 가까운 산으로 const seoul = mountains.reduce((a, b) => (Math.hypot(b.lat - SEOUL.lat, b.lon - SEOUL.lon) < Math.hypot(a.lat - SEOUL.lat, a.lon - SEOUL.lon) ? b : a)) const sel = mountains.find((m) => m.name === picked) return (

단풍 지도 · {md(today)}

서울 근교 {seoul.name} 절정 예상 {md(seoul.peak)}

한반도 지도 {mountains.map((m) => ( ))} {sel && (

{sel.name} {sel.region}
{STAGE[sel.stage].label} · 절정 예상 {md(sel.peak)}

)}
{(Object.keys(STAGE) as Stage[]).map((s) => ( {STAGE[s].label} ))}

출처: 산림청 2026 단풍절정 예측 · 단풍나무 잎 절반이 물든 때 기준

) }