import { useQuery } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { getSkyOptions, getSkyRankingOptions } from '../api/client/@tanstack/react-query.gen'
import type { BestTime, SkyPlanData } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { clockShort, loadOf } from './lib'
import { useRegion } from './regionContext'
import { MapLink, Sec, Skel, StateBox } from './ui'
function LiSkel({ ghost = false }: { ghost?: boolean }) {
return (
)
}
// 다른 탭 히어로보다 짧게. 배경은 하늘 상황별 색(b-sit-1~5), 아래에 동네 실루엣
const HERO = 'relative mx-3 mt-1 min-h-[230px] overflow-hidden rounded-[32px] px-5 pt-5 pb-14 text-white'
const THREE = [0, 1, 2]
const RANK_SKELS = Array.from({ length: 8 }, (_, i) => i)
/** 히어로엔 해 지는 시각과 하늘 상황 한 줄만. 결론·이유는 아래 카드로 */
function HeroBody({ plan, sunset }: { plan?: SkyPlanData; sunset?: string }) {
const v = (node: ReactNode, w: string) => (plan ? node : )
return (
{v(sunset && clockShort(sunset), 'w-[150px]')}
{v(plan?.situation_label ?? plan?.headline, 'w-[190px]')}
)
}
/** 결론과 이유, 예보 모델이 얼마나 같은 예보를 냈는지, 점수(작게) */
function Verdict({ plan }: { plan?: SkyPlanData }) {
const v = (node: ReactNode, w: string) => (plan ? node : )
const agree = plan?.models_total ? `예보 모델 ${plan.models_total}개 중 ${plan.models_agree}개가 같은 예보` : ''
return (
{v(plan?.headline, 'w-20')}
{v(plan?.reason, 'w-[220px]')}
{v(plan && [agree, `노을 점수 ${plan.score}`].filter(Boolean).join(' · '), 'w-48')}
)
}
/** 골든아워 → 해 짐 → 블루아워 */
function Timeline({ rows }: { rows?: BestTime[] }) {
return (
{(rows ?? THREE.map(() => undefined)).map((t, i) => (
-
{t ? clockShort(t.at) : }
{t ? t.label : }
))}
)
}
function SpotsSkel() {
return (
<>
>
)
}
function RankSkel() {
return (
{RANK_SKELS.map((i) => (
))}
)
}
function Li({ no, title, sub, right, mine = false, place }: { no: number; title: string; sub?: string | null; right: string; mine?: boolean; place?: string }) {
return (
{no}
{place ? {title} : title}
{mine && 내 지역}
{sub || '\u00a0'}
{right}
)
}
export function SkyPage() {
const { region } = useRegion()
const sky = useQuery(getSkyOptions({ query: { region: region.code } }))
const ranking = useQuery(getSkyRankingOptions())
const load = loadOf(sky)
const rankLoad = loadOf(ranking)
const plan = sky.data?.plan ?? undefined
const spots = (sky.data?.spots ?? []).slice(0, 3)
const items = (ranking.data?.items ?? []).slice(0, 8)
const target = sky.data?.days?.find((d) => d.day === plan?.day)
const sunset = plan?.timeline?.find((t) => t.kind === 'sun')?.at
return (
{/* 히어로 상자는 불러오는 중·실패·빈 값 모두 같은 크기 */}
{/* 하늘 위 흰 글씨 대비가 모자라 어두운 바탕을 깐다 */}
{plan?.when ?? '오늘'} 노을 · {region.name}
{plan || load === 'loading' ? (
) : (
sky.refetch()} empty="오늘 노을 정보가 없어요." hold={} className="inset-x-0 top-1.5 bottom-0" />
)}
{(plan || load === 'loading') && }
{plan?.timeline?.length || load === 'loading' ? (
) : (
} className="inset-x-3 top-3 bottom-0" />
)}
{/* 더 나은 날이 있을 때만 */}
{plan?.outlook && {plan.outlook}
}
{spots.length ? (
{spots.map((p) => (
))}
{/* 3곳이 안 되면 빈 줄로 스켈레톤 높이를 지켜 아래 순위가 밀리지 않게 */}
{THREE.slice(spots.length).map((i) => (
))}
) : load === 'loading' ? (
) : (
// 실패 안내·다시 시도는 위 히어로에 한 번만. 여기는 목록 자리만 지킨다
} className="inset-x-3 top-3 bottom-0" />
)}
{items.length ? (
) : rankLoad === 'loading' ? (
) : (
ranking.refetch()} empty="순위가 아직 없어요." hold={} className="inset-x-3 top-1.5 bottom-0" />
)}
)
}