"use client";
import { useState, useEffect, useCallback } from "react";
const STORAGE_KEY = "om:ai-assistant:visibility";
const DEFAULT_VISIBILITY = {
  enabled: false
  // Hidden by default
};
function useAiAssistantVisibility() {
  const [visibility, setVisibilityState] = useState(DEFAULT_VISIBILITY);
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    try {
      const stored = localStorage.getItem(STORAGE_KEY);
      if (stored) {
        const parsed = JSON.parse(stored);
        setVisibilityState(parsed);
      }
    } catch {
    }
    setIsLoaded(true);
  }, []);
  useEffect(() => {
    const handleStorageChange = (event) => {
      if (event.key === STORAGE_KEY && event.newValue) {
        try {
          const parsed = JSON.parse(event.newValue);
          setVisibilityState(parsed);
        } catch {
        }
      }
    };
    const handleVisibilityChange = (event) => {
      setVisibilityState(event.detail);
    };
    window.addEventListener("storage", handleStorageChange);
    window.addEventListener("om:ai-assistant-visibility-change", handleVisibilityChange);
    return () => {
      window.removeEventListener("storage", handleStorageChange);
      window.removeEventListener("om:ai-assistant-visibility-change", handleVisibilityChange);
    };
  }, []);
  const setVisibility = useCallback((newVisibility) => {
    setVisibilityState((prev) => {
      const updated = { ...prev, ...newVisibility };
      try {
        localStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
        window.dispatchEvent(
          new CustomEvent("om:ai-assistant-visibility-change", { detail: updated })
        );
      } catch {
      }
      return updated;
    });
  }, []);
  const toggleEnabled = useCallback(() => {
    setVisibility({ enabled: !visibility.enabled });
  }, [visibility.enabled, setVisibility]);
  return {
    visibility,
    isLoaded,
    setVisibility,
    toggleEnabled,
    isEnabled: visibility.enabled
  };
}
export {
  useAiAssistantVisibility
};
//# sourceMappingURL=useAiAssistantVisibility.js.map
