"use client";
import * as React from "react";
import { useCurrentUserId } from "@open-mercato/ui/backend/utils/useCurrentUserId";
import {
  DEFAULT_CALENDAR_PREFERENCES,
  calendarPreferencesStorageKey,
  parseStoredCalendarPreferences
} from "../../lib/calendar/preferences.js";
function useCalendarPreferences() {
  const userId = useCurrentUserId();
  const scopeKey = userId || "anon";
  const [preferences, setPreferencesState] = React.useState(DEFAULT_CALENDAR_PREFERENCES);
  const [hydrated, setHydrated] = React.useState(false);
  React.useEffect(() => {
    if (typeof window === "undefined") return;
    let raw = null;
    try {
      raw = window.localStorage.getItem(calendarPreferencesStorageKey(scopeKey));
    } catch {
      raw = null;
    }
    setPreferencesState(parseStoredCalendarPreferences(raw));
    setHydrated(true);
  }, [scopeKey]);
  const setPreferences = React.useCallback(
    (next) => {
      setPreferencesState(next);
      if (typeof window === "undefined") return;
      try {
        window.localStorage.setItem(calendarPreferencesStorageKey(scopeKey), JSON.stringify(next));
      } catch {
      }
    },
    [scopeKey]
  );
  return { preferences, setPreferences, hydrated, userId: userId || null };
}
export {
  useCalendarPreferences
};
//# sourceMappingURL=useCalendarPreferences.js.map
