import { useEffect, useRef, useState, type CSSProperties, type MouseEvent, type ReactNode } from 'react' import { createPortal } from 'react-dom' import { PostType, SlotTone, type GakSlide, type HoursSlide, type PlanSlide, type PostData, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '../api/client/types.gen' import { SOCIAL } from '../lib/platform' import { cx } from '../lib/utils' import { cardBg, clockShort, fall } from './lib' import type { SlideBg } from './types' import { deg } from './weatherText' import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query' import { likePostMutation, unlikePostMutation } from '../api/client/@tanstack/react-query.gen' import { useAuth } from './authContext' import { useSheet } from './sheetContext' import { CommentIcon, HeartIcon, SendIcon } from './svg' import { useCarousel } from './carousel' import { Arrows, Credit, Ic, Rows, Skel, TAP44, Thumb } from './ui' 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'], } type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide 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 (post.post_type === PostType.EVENT) 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) } const DARK = new Set(['dusk', 'night']) 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]' function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) { 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 && (