import type { GakSlide, HoursSlide, PlanSlide, PostData, RowsSlide, SunsetSlide, WeekSlide } from '@nalssigak/shared/api/client/types.gen'; import { PostType, SlotTone } from '@nalssigak/shared/api/client/types.gen'; import { cardBg, clockShort } from '@nalssigak/shared/lib'; import type { SlideBg } from '@nalssigak/shared/lib/types'; import { deg } from '@nalssigak/shared/lib/weatherText'; import { Image } from 'expo-image'; import { LinearGradient } from 'expo-linear-gradient'; import { useState, type ReactNode } from 'react'; import { Pressable, StyleSheet, View } from 'react-native'; import { Text } from '@/components/text'; import Svg, { Polygon } from 'react-native-svg'; import { MoonArt } from '@/components/moon'; import { Credit, Ic, Rows, Thumb } from '@/components/ui'; import { CARD_BG } from '@/lib/colors'; import { useSheet } from '@/lib/sheet'; import { imageUri } from '@/lib/site'; import { useSky } from '@/lib/sky'; export type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide; type Stops = readonly [string, string, ...string[]]; const GAK_BG: SlideBg[] = ['butter', 'peach', 'lilac']; const ROW_ICON_BG: Record = { umbrella: 'lilac', vent: 'mint', sunset: 'peach', thermo: 'sky', maple: 'peach', moon: 'lilac', glasses: 'butter' }; const DARK = new Set(['dusk', 'night']); const chunk = (items: T[], n: number) => Array.from({ length: Math.ceil(items.length / n) }, (_, i) => items.slice(i * n, i * n + n)); // 노을 하늘 상황(1 가려짐 2 낮은 구름 3 물들 구름 적음 4 넓게 물듦 5 두꺼움)별 하늘, 시간 칸 색 (웹 .b-sit-*, .b-cut-*) const SIT_BG: Record = { 1: { colors: ['#6f7690', '#9aa0b4', '#b9b4c0'], locations: [0, 0.55, 1] }, 2: { colors: ['#7a7f9c', '#a7a3bb', '#c9b8b8'], locations: [0, 0.55, 1] }, 3: { colors: ['#4b5aa8', '#7f86c6', '#e9b9a8', '#ffb27a', '#ff8a4c'], locations: [0, 0.38, 0.68, 0.86, 1] }, 4: { colors: ['#5b3f9e', '#c2559a', '#ff7a6a', '#ffb35c'], locations: [0, 0.4, 0.68, 1] }, 5: { colors: ['#6a6aa0', '#a98fb4', '#e3b1a0'], locations: [0, 0.55, 1] }, }; const CUT_BG: Stops[] = [ ['#9fd0ff', '#ffd79a', '#ff9a5c'], ['#8f7cf0', '#ff6f8e', '#ff8a4c'], ['#34306e', '#7a5cc8'], ]; // 건물 실루엣 (웹 .b-skyline clip-path) const SKYLINE = '0,55 8,55 8,30 15,30 15,50 22,50 22,10 28,10 28,45 36,45 36,25 44,25 44,55 52,55 52,35 60,35 60,5 66,5 66,40 74,40 74,20 82,20 82,50 90,50 90,30 100,30 100,100 0,100'; const HOUR_TONE: Record = { [SlotTone.NIGHT]: { bg: '#e3e7ff', edge: '#c7cff5' }, [SlotTone.SUNSET]: { bg: '#ffe3d2', edge: '#ffc19f' }, }; /** 배경색은 API에 없어 글 종류·아이콘으로 고른다 */ export function slideBg(post: PostData, slide: Slide): SlideBg { if (slide.kind === 'hours') return 'sky'; if (slide.kind === 'sunset') return 'dusk'; if (slide.kind === 'week') return 'mint'; if (slide.kind === 'plan') return slide.eyebrow.startsWith('일') ? 'peach' : 'butter'; if (slide.kind === 'gak') return GAK_BG[post.post_id % GAK_BG.length]; if (post.post_type === PostType.EVENT || post.post_type === PostType.MOON) return 'night'; if (post.post_type === PostType.TIP) return 'sky'; if (post.post_type === PostType.AIR) return slide.icon === 'vent' ? 'mint' : 'lilac'; if (post.post_type === PostType.DAY_TRIP) return slide.image ? 'night' : 'mint'; return (ROW_ICON_BG[slide.icon] ?? cardBg(slide.icon, post.post_id)) as SlideBg; } function Base({ colors, locations, children }: { colors: Stops; locations?: readonly [number, number, ...number[]]; children: ReactNode }) { return ( {children} ); } function Eyebrow({ children, light, className }: { children: ReactNode; light?: boolean; className?: string }) { return {children}; } function Big({ children, light, className }: { children: ReactNode; light?: boolean; className?: string }) { return {children}; } function Pic({ name, widthPct = 42 }: { name: string; widthPct?: number }) { return ( ); } // 달 포스트 밤하늘 별: [left %, top %, 크기] const STARS: [number, number, number][] = [ [8, 34, 2], [18, 52, 1.5], [30, 40, 2.5], [44, 30, 1.5], [52, 58, 2], [62, 22, 1.5], [90, 18, 2], [94, 44, 1.5], [12, 70, 1.5], [38, 66, 2], [76, 74, 1.5], [86, 64, 2], [24, 12, 1.5], [70, 10, 2.5], ]; /** 달 포스트 그림: 아이콘 대신 오늘 밤 실제 모양의 달과 별 */ function MoonPic({ pct, waxing }: { pct: number; waxing: boolean }) { const [w, setW] = useState(0); return ( setW(e.nativeEvent.layout.width)}> {STARS.map(([x, y, s]) => ( ))} {w > 0 && ( )} ); } export function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) { const { open } = useSheet(); const { kind } = useSky(); const palette = CARD_BG[kind === 'night' ? 'night' : 'day']; const colors = palette[bg] ?? palette.sky; const light = DARK.has(bg); if (slide.kind === 'hours') { const temps = slide.hours.flatMap((h) => (h.temp_c == null ? [] : [h.temp_c])); const lo = Math.min(...temps); const span = Math.max(...temps) - lo || 1; return ( {slide.eyebrow} {slide.line} {/* 웹 grid-cols-4: 4칸씩 줄을 나눈다 */} {chunk(slide.hours, 4).map((row) => ( {row.map((h) => { const tone = HOUR_TONE[h.tone ?? '']; return ( {h.temp_c != null && } {h.label} {deg(h.temp_c)} ); })} {/* 마지막 줄이 모자라면 빈 칸으로 너비를 맞춘다 */} {Array.from({ length: 4 - row.length }, (_, i) => ( ))} ))} ); } if (slide.kind === 'gak') return ( 오늘의 각 · {slide.rank}위 {slide.line} {slide.score} {slide.name} {slide.summary} open({ type: 'gak', indexId: slide.index_id })} className="mt-3 self-start rounded-full border-b-[5px] border-orange-deep bg-orange px-4 py-[9px]"> 계산 근거 보기 ); if (slide.kind === 'sunset') { const sit = slide.situation ? SIT_BG[slide.situation] : undefined; return ( {slide.eyebrow} {/* 노을 탭 히어로와 같은 순서: 결론 → 가장 붉을 때 → 쉬운 이유 */} {slide.headline ?? slide.grade_label} {slide.line && {slide.line}} {slide.cuts.map((c, i) => ( {clockShort(c.at)} {c.label} ))} ); } if (slide.kind === 'week') return ( {slide.eyebrow} {slide.line} {/* 칸은 제목 바로 아래, 팁만 맨 아래로 */} {slide.days.map((d) => ( {d.weekday} {d.day.split('-').slice(1).map(Number).join('.')} {deg(d.temp_min_c)} → {deg(d.temp_max_c)} 비 {d.rain_prob ?? '?'}%{d.temp_min_c != null && d.temp_max_c != null && ` · 일교차 ${Math.round(d.temp_max_c - d.temp_min_c)}°`} {d.gaks && d.gaks.length > 0 && ( 이날 할 만한 각 {d.gaks.map((g) => ( {g.name} {g.score} ))} )} ))} {slide.tip && {slide.tip}} ); if (slide.kind === 'plan') { const credits = [...new Set(slide.steps.flatMap((st) => (st.image && st.image_credit ? [st.image_credit] : [])))]; return ( {slide.eyebrow} {slide.line} {slide.steps.map((st, i) => ( {st.time} {st.title} {st.sub} {st.image && } ))} {credits.length > 0 && 사진 {credits.join(' · ')}} ); } if (slide.kind === 'rows' && slide.image) return ( {slide.image_credit && } {slide.eyebrow} {slide.line} ); return ( {slide.moon_pct != null && } {slide.eyebrow} {slide.line} {slide.moon_pct == null && } ); }