"use client";
import { useState, useEffect } from "react";
// Re-export shared utilities and types
export { createLocationState, isLocationStateEntry, resolveLocationStateEntries, } from "./location-state-shared.js";
export function useLocationState(definition) {
    const [state, setState] = useState(() => {
        if (typeof window === "undefined")
            return undefined;
        if (definition) {
            return window.history.state?.[definition.__rsc_ls_key];
        }
        // Legacy: return history.state.state for backwards compatibility
        return window.history.state?.state;
    });
    useEffect(() => {
        const handlePopstate = () => {
            if (definition) {
                setState(window.history.state?.[definition.__rsc_ls_key]);
            }
            else {
                setState(window.history.state?.state);
            }
        };
        window.addEventListener("popstate", handlePopstate);
        return () => window.removeEventListener("popstate", handlePopstate);
    }, [definition]);
    return state;
}
//# sourceMappingURL=location-state.js.map