// src/hooks/useA11yKeyboardShortcut.ts
import { useEffect } from "react";

// src/store/accessibilityStore.ts
import { create } from "zustand";
import { devtools, persist } from "zustand/middleware";
var DEFAULT_ACCESSIBILITY_PREFERENCES = {
  contrastMode: "normal",
  saturationMode: "normal",
  fontSize: 0,
  letterSpacing: 0,
  lineSpacing: 0,
  highlightLinks: false,
  pauseAnimations: false,
  bigCursor: false,
  dyslexiaFont: false,
  readingAid: "none",
  keyboardShortcut: true,
  colorBlindMode: "none" /* None */,
  ttsMode: "off",
  ttsRate: 1,
  ttsVoiceId: null,
  librasEnabled: false
};
var useAccessibilityStore = create()(
  devtools(
    persist(
      (set) => ({
        ...DEFAULT_ACCESSIBILITY_PREFERENCES,
        isPanelOpen: false,
        ttsStatus: "idle",
        setContrastMode: (contrastMode) => set({ contrastMode }),
        setSaturationMode: (saturationMode) => set({ saturationMode }),
        setFontSize: (fontSize) => set({ fontSize }),
        setLetterSpacing: (letterSpacing) => set({ letterSpacing }),
        setLineSpacing: (lineSpacing) => set({ lineSpacing }),
        setHighlightLinks: (highlightLinks) => set({ highlightLinks }),
        setPauseAnimations: (pauseAnimations) => set({ pauseAnimations }),
        setBigCursor: (bigCursor) => set({ bigCursor }),
        setDyslexiaFont: (dyslexiaFont) => set({ dyslexiaFont }),
        setReadingAid: (readingAid) => set({ readingAid }),
        setKeyboardShortcut: (keyboardShortcut) => set({ keyboardShortcut }),
        setColorBlindMode: (colorBlindMode) => set({ colorBlindMode }),
        setTTSMode: (ttsMode) => set({ ttsMode }),
        setTTSRate: (ttsRate) => set({ ttsRate }),
        setTTSVoiceId: (ttsVoiceId) => set({ ttsVoiceId }),
        setTTSStatus: (ttsStatus) => set({ ttsStatus }),
        setLibrasEnabled: (librasEnabled) => set({ librasEnabled }),
        resetPreferences: () => set({ ...DEFAULT_ACCESSIBILITY_PREFERENCES }),
        openPanel: () => set({ isPanelOpen: true }),
        closePanel: () => set({ isPanelOpen: false }),
        togglePanel: () => set((state) => ({ isPanelOpen: !state.isPanelOpen }))
      }),
      {
        name: "accessibility-store",
        // version 1: removeu `librasEnabled` da persistência (era custoso
        // recarregar VLibras a cada refresh). A migração limpa esse valor
        // de localStorages antigos para evitar auto-load surpresa.
        version: 1,
        // eslint-disable-next-line @typescript-eslint/no-explicit-any -- migrate works with arbitrary persisted shapes from older versions
        migrate: (persistedState) => {
          if (persistedState && typeof persistedState === "object" && "librasEnabled" in persistedState) {
            delete persistedState.librasEnabled;
          }
          return persistedState;
        },
        partialize: (state) => ({
          contrastMode: state.contrastMode,
          saturationMode: state.saturationMode,
          fontSize: state.fontSize,
          letterSpacing: state.letterSpacing,
          lineSpacing: state.lineSpacing,
          highlightLinks: state.highlightLinks,
          pauseAnimations: state.pauseAnimations,
          bigCursor: state.bigCursor,
          dyslexiaFont: state.dyslexiaFont,
          readingAid: state.readingAid,
          keyboardShortcut: state.keyboardShortcut,
          colorBlindMode: state.colorBlindMode,
          ttsRate: state.ttsRate,
          ttsVoiceId: state.ttsVoiceId
          // ttsMode e librasEnabled NÃO são persistidos:
          // - ttsMode: o leitor sempre começa desligado ao recarregar
          //   a página para evitar comportamento confuso
          // - librasEnabled: o VLibras é pesado (~MBs de assets); auto-
          //   carregar a cada refresh seria custoso e surpreendente. O
          //   usuário ativa explicitamente quando precisa.
        })
      }
    ),
    { name: "accessibility-store" }
  )
);

// src/hooks/useA11yKeyboardShortcut.ts
var useA11yKeyboardShortcut = () => {
  const enabled = useAccessibilityStore((s) => s.keyboardShortcut);
  const togglePanel = useAccessibilityStore((s) => s.togglePanel);
  useEffect(() => {
    if (!enabled) return;
    const handler = (event) => {
      if (!event.altKey || event.key.toLowerCase() !== "a") return;
      if (event.repeat) return;
      const target = event.target;
      if (target) {
        const tag = target.tagName;
        if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || target.isContentEditable) {
          return;
        }
      }
      event.preventDefault();
      togglePanel();
    };
    globalThis.addEventListener("keydown", handler);
    return () => globalThis.removeEventListener("keydown", handler);
  }, [enabled, togglePanel]);
};
export {
  useA11yKeyboardShortcut
};
//# sourceMappingURL=index.mjs.map