{
  "version": 3,
  "sources": ["js/components/theme.js"],
  "sourcesContent": ["/**\n * Clinexa – Theme Switcher\n * Handles dark/light mode toggle with icon swap (moon/sun)\n * Single source of truth: class on <html> (\"dark\" | \"light\")\n */\n\nconst THEME_KEY = \"clinexa-theme\";\n// Turbo snapshots copy attributes, but not event listeners, to new nodes.\nconst boundThemeButtons = new WeakSet();\n// Keep an explicit choice on this page if browser storage is unavailable.\nconst unsavedThemes = new WeakMap();\n\nexport function initTheme() {\n  const root = document.documentElement;\n  // Support both the standard topbar toggle and the dropdown variant\n  const toggleBtns = [\n    document.getElementById(\"theme-toggle\"),\n    document.getElementById(\"theme-toggle-dropdown\"),\n  ].filter(Boolean);\n\n  // Only an explicit site preference enables dark mode.\n  let savedTheme = null;\n  try {\n    savedTheme = localStorage.getItem(THEME_KEY);\n  } catch {\n    // Storage can be blocked by browser privacy settings.\n  }\n  root.classList.toggle(\"dark\", (unsavedThemes.get(root) ?? savedTheme) === \"dark\");\n\n  // Sync icon to current theme\n  syncIcon(root.classList.contains(\"dark\"));\n\n  if (toggleBtns.length === 0) return;\n\n  // Toggle handler\n  const toggleTheme = (e) => {\n    e.stopPropagation();\n\n    const isDark = root.classList.contains(\"dark\");\n    const nextTheme = isDark ? \"light\" : \"dark\";\n\n    // Kill transitions for atomic swap\n    root.classList.add(\"no-transition\");\n\n    // Toggle dark class\n    root.classList.toggle(\"dark\", !isDark);\n\n    // Persist choice\n    try {\n      localStorage.setItem(THEME_KEY, nextTheme);\n      unsavedThemes.delete(root);\n    } catch {\n      unsavedThemes.set(root, nextTheme);\n    }\n\n    // Update icon\n    syncIcon(!isDark);\n\n    // Force reflow\n    void root.offsetHeight;\n\n    // Re-enable transitions\n    root.classList.remove(\"no-transition\");\n\n    // Dispatch event for charts\n    window.dispatchEvent(\n      new CustomEvent(\"clinexa:theme-change\", {\n        detail: { theme: nextTheme },\n      })\n    );\n\n    // Close the dropdown if it was opened from there\n    const dropdownMenu = document.querySelector(\"#theme-toggle-dropdown\")?.closest(\"[data-dropdown]\")?.querySelector(\"[data-dropdown-menu]\");\n    if (dropdownMenu) {\n      dropdownMenu.classList.remove(\"opacity-100\", \"pointer-events-auto\", \"scale-100\");\n      dropdownMenu.classList.add(\"opacity-0\", \"pointer-events-none\", \"scale-95\");\n      const toggle = document.querySelector(\"#theme-toggle-dropdown\")?.closest(\"[data-dropdown]\")?.querySelector(\"[data-dropdown-toggle]\");\n      if (toggle) toggle.setAttribute(\"aria-expanded\", \"false\");\n    }\n  };\n\n  toggleBtns.forEach((btn) => {\n    if (boundThemeButtons.has(btn)) return;\n    boundThemeButtons.add(btn);\n    btn.addEventListener(\"click\", toggleTheme);\n  });\n\n  function syncIcon(isDark) {\n    const icons = [\n      document.getElementById(\"theme-icon\"),\n      document.querySelector(\"#theme-toggle-dropdown .ui-icon, #theme-toggle-dropdown i\"),\n    ].filter(Boolean);\n    icons.forEach((icon) => {\n      if (isDark) {\n        icon.classList.remove(\"ph-moon\");\n        icon.classList.add(\"ph-sun\");\n      } else {\n        icon.classList.remove(\"ph-sun\");\n        icon.classList.add(\"ph-moon\");\n      }\n    });\n  }\n}\n"],
  "mappings": ";;AAMA,MAAMA,IAAY,iBAEZC,IAAoB,oBAAI,QAAQ,GAEhCC,IAAgB,oBAAI,QAAQ;AAE3B,gBAAS,YAAY;AAC1B,QAAMC,IAAO,SAAS,iBAEhBC,IAAa;AAAA,IACjB,SAAS,eAAe,cAAc;AAAA,IACtC,SAAS,eAAe,uBAAuB;AAAA,EACjD,EAAE,OAAO,OAAO;AAGhB,MAAIC,IAAa;AACjB,MAAI;AACF,IAAAA,IAAa,aAAa,QAAQL,CAAS;AAAA,EAC7C,QAAQ;AAAA,EAER;AAMA,MALAG,EAAK,UAAU,OAAO,SAASD,EAAc,IAAIC,CAAI,KAAKE,OAAgB,MAAM,GAGhFC,EAASH,EAAK,UAAU,SAAS,MAAM,CAAC,GAEpCC,EAAW,WAAW,EAAG;AAG7B,QAAMG,IAAc,gBAAAC,EAAA,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AU,OAAO,SAAS,GAC/BA,EAAK,UAAU,IAAI,QAAQ,MAE3BA,EAAK,UAAU,OAAO,QAAQ,GAC9BA,EAAK,UAAU,IAAI,SAAS;AAAA,IAEhC,CAAC;AAAA,EACH;AAdS,EAAAP,EAAAF,GAAA;AAeX;AA1FgBE,EAAA;",
  "names": ["THEME_KEY", "boundThemeButtons", "unsavedThemes", "root", "toggleBtns", "savedTheme", "syncIcon", "toggleTheme", "__name", "e", "isDark", "nextTheme", "dropdownMenu", "toggle", "btn", "icon"]
}
