import { useState, type CSSProperties, type ReactNode } from 'react' import { Link } from 'react-router' import { cx } from '../lib/utils' import { useCarousel, type Carousel } from './carousel' import { AVATAR_COLORS, iconSrc, moodEmoji, naverMap, type Load } from './lib' type IcProps = { name: string; className?: string; alt?: string; style?: CSSProperties } export function Ic({ name, className, alt = '', style }: IcProps) { const src = iconSrc(name) if (!src) return return {alt} } /** 사진 출처 표기 (공공누리 조건). 사진 위에서도 읽히게 반투명 배경. 위치는 className 으로 */ export function Credit({ text, className = 'right-1 bottom-1' }: { text: string; className?: string }) { return {text} } type ThumbProps = { image?: string | null; icon: string; credit?: string | null; className?: string; iconClassName?: string; creditClassName?: string; children?: ReactNode } /** 사진이 있으면 사진(+출처), 없거나 못 불러오면 아이콘 */ export function Thumb({ image, icon, credit, className, iconClassName, creditClassName, children }: ThumbProps) { const [failed, setFailed] = useState(null) const photo = image && image !== failed ? image : null return ( {photo ? setFailed(photo)} className="absolute inset-0 size-full object-cover" /> : } {photo && credit && } {children} ) } type AvatarProps = { character: string; color?: string | null; mood?: string | null; size?: number; className?: string } /** 프로필 동그라미: 고른 배경색 위에 캐릭터, 오른쪽 위에 오늘 기분 */ export function Avatar({ character, color, mood, size = 34, className }: AvatarProps) { const emoji = moodEmoji(mood) return ( {emoji && ( )} ) } type SecProps = { title: string; sub?: ReactNode; more?: { to: string; label?: string }; className?: string } export function Sec({ title, sub, more, className }: SecProps) { return (

{title}

{sub &&

{sub}

}
{more && ( {more.label ?? '전체 보기'} )}
) } /** PC(마우스)에서만 보이는 좌우 화살표 */ export function Arrows({ api, prev, next, className }: { api: Carousel; prev: boolean; next: boolean; className?: string }) { const btn = 'absolute top-1/2 z-[3] hidden size-8 -translate-y-1/2 cursor-pointer place-items-center rounded-full bg-white/90 text-lg font-extrabold text-[#28304a] shadow-[0_4px_10px_rgb(40_48_74/0.18)] pointer-fine:grid' return ( <> {prev && ( )} {next && ( )} ) } const STRIP = { align: 'start', dragFree: true, containScroll: 'trimSnaps' } as const /** Rail 과 같은 틀(여백·간격)로 스켈레톤 칸을 늘어놓는다. 넘기기·화살표는 없음 */ export function SkelRail({ children, className }: { children: ReactNode; className?: string }) { return ( ) } export function Rail({ children, className, label }: { children: ReactNode; className?: string; label?: string }) { const { ref, api, prev, next } = useCarousel(STRIP) return (
{children}
) } // 보이는 크기는 두고 누르는 영역만 가운데 44×44로 넓힌다 (위치 지정된 요소에 붙인다) export const TAP44 = 'after:absolute after:top-1/2 after:left-1/2 after:size-11 after:-translate-1/2' type ChipsProps = { items: readonly (readonly [K, string])[]; value: K; onChange: (k: K) => void; label: string; disabled?: boolean } export function Chips({ items, value, onChange, label, disabled }: ChipsProps) { return ( {items.map(([k, l]) => ( ))} ) } function ChipStrip({ children, label }: { children: ReactNode; label: string }) { const { ref, api, prev, next } = useCarousel(STRIP) return (
{children}
) } type SkelProps = { className?: string; shape?: boolean; style?: CSSProperties } /** * 불러오는 동안 자리만 잡는 막대. 기본은 글자 자리: 감싼 글자 요소 안에 넣으면 그 줄 높이(1lh)를 그대로 차지한다. * shape 면 className 으로 준 크기의 블록(사진·동그라미 자리). */ export function Skel({ className, shape = false, style }: SkelProps) { return (