// --- Theme --------------------------------------------------------------------
var _THEMES = ['dark', 'light', 'auto'];
function _getTheme() { return document.documentElement.getAttribute('data-theme') || 'auto'; }
function _applyTheme(t: string | undefined) {
  if (t === 'auto') { document.documentElement.removeAttribute('data-theme'); localStorage.removeItem('theme'); }
  else { document.documentElement.setAttribute('data-theme', t); localStorage.setItem('theme', t); }
  _updateThemeBtn();
}
export function cycleTheme() {
  var cur = _getTheme(), idx = _THEMES.indexOf(cur);
  _applyTheme(_THEMES[(idx + 1) % _THEMES.length]);
}
function _detectDR() {
  return !!(document.querySelector('meta[name="darkreader"]') ||
    document.querySelector('style[data-darkreader-style]') ||
    document.documentElement.getAttribute('data-darkreader-mode'));
}
function _updateThemeBtn() {
  var btn = document.getElementById('theme-toggle');
  if (!btn) return;
  var t = _getTheme(), dr = _detectDR();
  var lbl = { dark: '☾ dark', light: '☀ light', auto: '⊙ auto' };
  btn.textContent = (dr ? 'DR · ' : '') + (lbl[t] || lbl.auto);
  btn.title = dr ? 'DarkReader active - controlling theme' : ('Theme: ' + t + ' (click to cycle)');
}
window.addEventListener('DOMContentLoaded', _updateThemeBtn);
