import { useEffect, useRef, useState, type CSSProperties, type MouseEvent, type ReactNode, type RefObject } from 'react' import { createPortal } from 'react-dom' import { PostType, SlotTone, type GakSlide, type HoursSlide, type ImageSlide, type PlanSlide, type PostData, type PostReaction, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '@nalssigak/shared/api/client/types.gen' import { API_BASE_URL } from '../api/setup' import { cx } from '../lib/utils' import { cardBg, clockShort } from '@nalssigak/shared/lib' import { fall } from './lib' import type { SlideBg } from '@nalssigak/shared/lib/types' import { deg } from '@nalssigak/shared/lib/weatherText' import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query' import { likePostMutation, unlikePostMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen' import { usePinnedLike, type PinnedKey } from './pinnedLike' import { useSheet } from './sheetContext' import { CommentIcon, HeartIcon, SendIcon } from './svg' import { useCarousel } from './carousel' import { MoonArt } from './moon' import { Arrows, Credit, Ic, Rows, Skel, TAP44, Thumb } from './ui' import { track } from '../lib/analytics' const ACCOUNTS: Record = { [PostType.WEATHER]: ['오늘 날씨', 'sun'], [PostType.GAK]: ['오늘의 각', 'rabbit'], [PostType.SUNSET]: ['노을', 'sunset'], [PostType.SEASON]: ['계절 소식', 'maple'], [PostType.EVENT]: ['가까운 행사', 'fireworks'], [PostType.TIP]: ['날씨 상식', 'bulb'], [PostType.WEEK]: ['주말 예보', 'calendar'], [PostType.ALERT]: ['생활 알림', 'umbrella'], [PostType.TOMORROW]: ['내일 미리보기', 'moon'], [PostType.QUOTE]: ['오늘의 한 문장', 'letter'], [PostType.WEEKEND_PLAN]: ['주말 플랜', 'calendar'], [PostType.AIR]: ['미세먼지', 'vent'], [PostType.DAY_TRIP]: ['당일치기', 'picnic'], [PostType.MOON]: ['오늘 밤 달', 'moon'], [PostType.UV]: ['자외선', 'glasses'], [PostType.HERO]: ['오늘 날씨', 'sun'], [PostType.TODAY_GAK]: ['오늘의 각', 'rabbit'], [PostType.FOLIAGE]: ['단풍 지도', 'maple'], [PostType.EVENTS_BAND]: ['이번 주 가까운 행사', 'fireworks'], [PostType.SEASON_BAND]: ['이번 주 계절 이야기', 'fallen_leaf'], [PostType.CARD]: ['날씨각 카드', 'stars'], } type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide | ImageSlide 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' } /** 배경색은 API에 없어 글 종류·아이콘으로 고른다 */ 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 (slide.kind === 'image') return 'sky' if (post.post_type === PostType.MOON) return 'night' if (post.post_type === PostType.EVENT) return slide.image ? 'night' : 'peach' 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) } const DARK = new Set(['dusk', 'night']) // 그림 배경이 있는 각(code)과 장 수. 여러 장이면 글마다 돌려 쓴다 const BG_IMAGES: Record = { bike: 4, picnic: 1, hiking: 1, hangang: 1 } function bgImage(name: string, n: number, seed: number): CSSProperties { const file = n > 1 ? `${name}-${'abcd'[seed % n]}` : name return { backgroundImage: `url(/post-bg/${file}.webp)`, backgroundSize: 'cover', backgroundPosition: 'center' } } /** 그림 배경: 각은 각마다. 없으면 색 배경만 */ function slideImage(post: PostData, slide: Slide): CSSProperties | undefined { if (slide.kind === 'gak') return BG_IMAGES[slide.code] ? bgImage(slide.code, BG_IMAGES[slide.code], post.post_id) : undefined return undefined } function Lines({ text }: { text: string }) { return text.split('\n').map((t, i) => ( {i > 0 &&
} {t}
)) } function Eyebrow({ children, className }: { children: ReactNode; className?: string }) { return

{children}

} function Big({ children, className }: { children: ReactNode; className?: string }) { return

{children}

} function Pic({ name, className }: { name: string; className?: string }) { return ( ) } const slideBase = 'relative flex h-full w-full shrink-0 flex-col px-5 py-[22px]' // 달 포스트 밤하늘 별: [left %, top %, 크기 px] 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 }) { return ( <> ) } function SlideView({ slide, bg, img }: { slide: Slide; bg: SlideBg; img?: CSSProperties }) { const { open } = useSheet() 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.hours.map((h) => (
*]:relative', h.tone === SlotTone.NIGHT ? 'bg-[#e3e7ff] shadow-[inset_0_-5px_0_#c7cff5]' : h.tone === SlotTone.SUNSET ? 'bg-[#ffe3d2] shadow-[inset_0_-5px_0_#ffc19f]' : 'bg-white shadow-[inset_0_-5px_0_var(--shade)]', )} > {h.temp_c != null && (