/*
 * AIWK Theme JS
 * Bootstrap 5.3 data-bs-theme 기준으로 light/dark를 통일한다.
 */
(function () {
  var key = 'aiwk_theme';
  var root = document.documentElement;

  function getPreferredTheme() {
    var saved = localStorage.getItem(key);
    if (saved === 'light' || saved === 'dark') return saved;
    var current = root.getAttribute('data-bs-theme');
    if (current === 'light' || current === 'dark') return current;
    return 'light';
  }

  function updateLabels(theme) {
    var nodes = document.querySelectorAll('[data-aiwk-theme-label]');
    for (var i = 0; i < nodes.length; i++) nodes[i].innerHTML = theme;
  }

  window.aiwkSetTheme = function (theme) {
    if (theme !== 'light' && theme !== 'dark') theme = 'light';
    root.setAttribute('data-bs-theme', theme);
    localStorage.setItem(key, theme);
    updateLabels(theme);
  };

  window.aiwkSetTheme(getPreferredTheme());
})();
