import { TalkTopic } from '@nalssigak/shared/api/client/types.gen' import { kst } from '@nalssigak/shared/lib' /** 게임 8단계 그림을 바꾼다. 작은 것부터 큰 것 순서, 크기·색은 원래 단계 그대로 */ type GamePiece = { icon: string; name: string } /** * 기념일 꾸밈. 기간(KST, 양 끝 포함) 안에만 켜진다. 'MM-DD' 는 해마다, 'YYYY-MM-DD' 는 그해만(음력 기념일). * 새 기념일: 여기에 한 줄 + TalkTopic(backend/common/enums.py) + 그림(public/b/icons, lib.ts OWN) */ export type Holiday = { key: 'halloween' | 'pepero' | 'christmas' | 'chuseok' name: string ranges: readonly (readonly [string, string])[] topic: TalkTopic /** 글만 있는 사람 글 배경 (b.css b-bg-*) */ bg: string /** 낮 하늘 맨 위 색 = 노치 띠 색. 하늘 그라데이션은 b.css .b-skybg[data-h] */ notch: string /** 밤 하늘도 바꾸는 기념일만 */ nightNotch?: string game: readonly GamePiece[] } export const HOLIDAYS: readonly Holiday[] = [ { key: 'halloween', notch: '#ffad62', nightNotch: '#1c1030', name: '할로윈', ranges: [['10-31', '11-01']], topic: TalkTopic.HALLOWEEN, bg: 'night', game: [ { icon: 'candy', name: '사탕' }, { icon: 'lollipop', name: '막대사탕' }, { icon: 'spider', name: '거미' }, { icon: 'spider_web', name: '거미줄' }, { icon: 'bat', name: '박쥐' }, { icon: 'ghost', name: '유령' }, { icon: 'skull', name: '해골' }, { icon: 'jack_o_lantern', name: '호박등' }, ], }, { key: 'pepero', notch: '#e2b08e', name: '빼빼로데이', ranges: [['11-11', '11-11']], topic: TalkTopic.PEPERO, bg: 'peach', game: [ { icon: 'pepero_choco', name: '초코' }, { icon: 'pepero_almond', name: '아몬드' }, { icon: 'pepero_strawberry', name: '딸기' }, { icon: 'pepero_nude', name: '누드' }, { icon: 'pepero_pair', name: '한 쌍' }, { icon: 'pepero_bundle', name: '다발' }, { icon: 'pepero_box', name: '한 상자' }, { icon: 'pepero_basket', name: '바구니' }, ], }, { key: 'christmas', notch: '#95d8ac', name: '크리스마스', ranges: [['12-24', '12-25']], topic: TalkTopic.CHRISTMAS, bg: 'mint', game: [ { icon: 'xmas_candy_cane', name: '캔디케인' }, { icon: 'xmas_ornament', name: '장식볼' }, { icon: 'xmas_gingerbread', name: '진저쿠키' }, { icon: 'xmas_santa_hat', name: '산타 모자' }, { icon: 'xmas_stocking', name: '양말' }, { icon: 'xmas_wreath', name: '리스' }, { icon: 'xmas_santa', name: '산타' }, { icon: 'christmas_tree', name: '트리' }, ], }, { key: 'chuseok', notch: '#ffd77e', name: '추석', ranges: [['2027-09-14', '2027-09-16']], topic: TalkTopic.CHUSEOK, bg: 'butter', game: [ { icon: 'chestnut', name: '밤' }, { icon: 'pear', name: '배' }, { icon: 'apple', name: '사과' }, { icon: 'dango', name: '떡' }, { icon: 'rabbit', name: '토끼' }, { icon: 'maple', name: '단풍' }, { icon: 'moon_viewing', name: '달맞이' }, { icon: 'full_moon', name: '보름달' }, ], }, ] const pad = (n: number) => String(n).padStart(2, '0') function inRange([from, to]: readonly [string, string], y: number, md: string) { const day = from.length === 10 ? `${y}-${md}` : md return from <= day && day <= to } /** 미리 보기 기념일: 주소의 ?holiday= 를 탭이 닫힐 때까지 기억 */ function previewKey() { const q = new URLSearchParams(location.search).get('holiday') if (q) sessionStorage.setItem('holiday', q) return q ?? sessionStorage.getItem('holiday') } /** 오늘(KST) 켜진 기념일. ?holiday=christmas 로 미리 보기 */ export function currentHoliday(now = new Date()): Holiday | undefined { const preview = previewKey() if (preview) return HOLIDAYS.find((h) => h.key === preview) const { y, mo, d } = kst(now) const md = `${pad(mo)}-${pad(d)}` return HOLIDAYS.find((h) => h.ranges.some((r) => inRange(r, y, md))) } export const holidayByTopic = (t?: number) => HOLIDAYS.find((h) => h.topic === t)