"use client";
import * as React from "react";
const STORAGE_KEY_PREFIX = "staff.timesheets.projects.viewMode";
function storageKey(userKey) {
  return userKey ? `${STORAGE_KEY_PREFIX}:${userKey}` : STORAGE_KEY_PREFIX;
}
function readStoredMode(userKey) {
  if (typeof window === "undefined") return null;
  try {
    const raw = window.localStorage.getItem(storageKey(userKey));
    return raw === "cards" || raw === "table" ? raw : null;
  } catch {
    return null;
  }
}
function writeStoredMode(userKey, mode) {
  if (typeof window === "undefined") return;
  try {
    window.localStorage.setItem(storageKey(userKey), mode);
  } catch {
  }
}
function useProjectsViewMode({
  userKey,
  urlOverride,
  fallback = "table"
}) {
  const initial = React.useMemo(() => {
    if (urlOverride === "cards" || urlOverride === "table") return urlOverride;
    return readStoredMode(userKey) ?? fallback;
  }, [urlOverride, userKey, fallback]);
  const [mode, setMode] = React.useState(initial);
  React.useEffect(() => {
    if (urlOverride === "cards" || urlOverride === "table") {
      setMode(urlOverride);
    }
  }, [urlOverride]);
  const update = React.useCallback(
    (next) => {
      setMode(next);
      writeStoredMode(userKey, next);
    },
    [userKey]
  );
  return [mode, update];
}
export {
  useProjectsViewMode
};
//# sourceMappingURL=useProjectsViewMode.js.map
