import { createContext, useCallback, useContext, useRef, useState } from "react"; import type { ReactNode } from "react"; type LiftContextValue = { liftedIds: Set; alwaysLiftedIds: Set; setLiftedIds: (ids: string[]) => void; registerAlways: (id: string) => void; unregisterAlways: (id: string) => void; portalContainer: HTMLElement | null; setPortalContainer: (el: HTMLElement | null) => void; }; const LiftContext = createContext(null); export function useLift(): LiftContextValue { const ctx = useContext(LiftContext); if (!ctx) throw new Error("useLift must be used within LiftProvider"); return ctx; } export function LiftProvider({ children }: { children: ReactNode }) { const [liftedIds, setLiftedIdsRaw] = useState>(new Set()); const [alwaysLiftedIds, setAlwaysLiftedIds] = useState>(new Set()); const [portalContainer, setPortalContainer] = useState(null); const alwaysRef = useRef>(new Set()); const setLiftedIds = useCallback((ids: string[]) => { setLiftedIdsRaw(new Set(ids)); }, []); const registerAlways = useCallback((id: string) => { alwaysRef.current.add(id); setAlwaysLiftedIds(new Set(alwaysRef.current)); }, []); const unregisterAlways = useCallback((id: string) => { alwaysRef.current.delete(id); setAlwaysLiftedIds(new Set(alwaysRef.current)); }, []); return ( {children} ); }