import type { RegionData } from '@nalssigak/shared/api/client/types.gen' import type { MyGak } from './myGakState' import type { WeatherWhyPayload } from './weatherWhy' import { createContext, use } from 'react' /** square: 1:1 비율일 때 slides 대신 찍을 틀 (없으면 slides). url: 같이 보낼 링크 (없으면 사이트 주소) */ export type SharePayload = { title: string; slides: HTMLElement[]; square?: HTMLElement[]; url?: string } /** 지역 창 '고르기만' 모드: current 는 '지금 보는 곳'으로 표시할 지역 코드 */ export type RegionPick = { current: string; onPick: (r: RegionData) => void } /** 댓글이 달린 곳: 운영 포스트 또는 사람 글 */ export type CommentTarget = { postId: number } | { talkId: number } type CommentsState = { type: 'comments'; draft?: string } & CommentTarget export type SheetState = | { type: 'gak'; indexId: number } | { type: 'article'; articleId: number } | { type: 'share'; share: SharePayload } | CommentsState | { type: 'seasonWeek' } | { type: 'login'; then?: CommentsState; why?: 'level' } | { type: 'me' } /** pick: 앱 지역은 그대로 두고 고른 지역만 돌려받는 '고르기만' 모드 (위젯 페이지 미리보기). 창 상태는 방문 기록에 저장하지 않아 함수를 넣어도 된다 */ | { type: 'region'; pick?: RegionPick } | { type: 'mix'; shared?: MyGak } | { type: 'myGak'; gak: MyGak; shot?: HTMLElement | null } | { type: 'install' } | { type: 'weatherWhy'; why: WeatherWhyPayload } | { type: 'tarot' } | { type: 'level' } | { type: 'levelUp'; level: number } | { type: 'gameHelp' } | { type: 'contact' } | null /** 창이 열리며 쌓아 둔 방문 기록이 지금 맨 위인지. 창 안에서 주소를 옮기면 그 기록이 맨 위가 아니게 된다 */ export const sheetEntryOnTop = () => (window.history.state as { sheet?: boolean } | null)?.sheet === true export type SheetApi = { open: (s: Exclude) => void; close: () => void } export const SheetContext = createContext(null) export function useSheet() { const ctx = use(SheetContext) if (!ctx) throw new Error('useSheet must be used inside SheetProvider') return ctx }