import { create } from "zustand"; import type { StatisticsInputPendingSearch } from "@/shared/lib/stats-cd-input-navigation"; type Pending = { urlPath: string; tabKey: string; search: StatisticsInputPendingSearch | null; }; export interface StatisticsInputFocusStore { pending: Pending | null; /** `setPendingInputTab` 호출 시마다 증가 — 이미 해당 화면이 활성일 때도 탭 적용 effect가 돌도록 함 */ nonce: number; setPendingInputTab: ( urlPath: string, tabKey: string, search?: StatisticsInputPendingSearch | null, ) => void; takePendingForUrl: ( urlPath: string, ) => { tabKey: string; search: StatisticsInputPendingSearch | null } | undefined; } export const useStatisticsInputFocusStore = create( (set, get) => ({ pending: null, nonce: 0, setPendingInputTab: (urlPath, tabKey, search = null) => set((state) => ({ pending: { urlPath, tabKey, search: search ?? null }, nonce: state.nonce + 1, })), takePendingForUrl: (urlPath) => { const p = get().pending; if (!p || p.urlPath !== urlPath) return undefined; set({ pending: null }); return { tabKey: p.tabKey, search: p.search }; }, }), );