(function () {
"use strict";
const THEME_KEY = "rio-theme";
const root = document.documentElement;
function applyTheme(value) {
if (value === "dark" || value === "light") {
root.setAttribute("data-rio-theme", value);
} else {
root.removeAttribute("data-rio-theme");
}
}
function nextTheme(current) {
if (current === "light") return "dark";
if (current === "dark") return "system";
return "light";
}
function themeLabel(value) {
if (value === "light") return "Light";
if (value === "dark") return "Dark";
return "System";
}
function initTheme() {
let stored = null;
try { stored = localStorage.getItem(THEME_KEY); } catch (_) { }
if (stored === "light" || stored === "dark") applyTheme(stored);
const button = document.querySelector("[data-rio-theme-toggle]");
if (!button) return;
function refresh() {
const value = stored || "system";
button.textContent = themeLabel(value);
button.setAttribute("aria-label", "Theme: " + themeLabel(value));
}
refresh();
button.addEventListener("click", () => {
stored = nextTheme(stored || "system");
try {
if (stored === "system") localStorage.removeItem(THEME_KEY);
else localStorage.setItem(THEME_KEY, stored);
} catch (_) { }
applyTheme(stored);
refresh();
});
}
function initSidebar() {
const shell = document.querySelector(".rio-shell");
const toggle = document.querySelector("[data-rio-sidebar-toggle]");
if (!shell || !toggle) return;
toggle.addEventListener("click", () => {
const open = shell.getAttribute("data-sidebar") === "open";
if (open) shell.removeAttribute("data-sidebar");
else shell.setAttribute("data-sidebar", "open");
});
shell.addEventListener("click", (evt) => {
const link = evt.target.closest(".rio-sidebar-link");
if (link) shell.removeAttribute("data-sidebar");
});
}
function initDropdowns() {
const dropdowns = document.querySelectorAll("[data-rio-dropdown]");
if (!dropdowns.length) return;
dropdowns.forEach((dd) => {
const toggle = dd.querySelector(".rio-dropdown-toggle");
if (!toggle) return;
toggle.addEventListener("click", (e) => {
e.stopPropagation();
const open = dd.classList.toggle("is-open");
toggle.setAttribute("aria-expanded", String(open));
});
});
document.addEventListener("click", (e) => {
dropdowns.forEach((dd) => {
if (dd.classList.contains("is-open") && !dd.contains(e.target)) {
dd.classList.remove("is-open");
const t = dd.querySelector(".rio-dropdown-toggle");
if (t) t.setAttribute("aria-expanded", "false");
}
});
});
document.addEventListener("keydown", (e) => {
if (e.key !== "Escape") return;
dropdowns.forEach((dd) => {
if (!dd.classList.contains("is-open")) return;
dd.classList.remove("is-open");
const t = dd.querySelector(".rio-dropdown-toggle");
if (t) {
t.setAttribute("aria-expanded", "false");
t.focus();
}
});
});
}
function initBulkSelect() {
const form = document.querySelector("[data-rio-bulk]");
if (!form) return;
const all = form.querySelector("[data-rio-bulk-all]");
const idsInput = form.querySelector("[data-rio-bulk-ids]");
const countEl = form.querySelector("[data-rio-bulk-count]");
const clearBtn = form.querySelector("[data-rio-bulk-clear]");
const rows = Array.from(form.querySelectorAll("[data-rio-bulk-row]"));
if (!rows.length) return;
function refresh() {
const checked = rows.filter((r) => r.checked);
const count = checked.length;
idsInput.value = checked.map((r) => r.value).join(",");
if (countEl) countEl.textContent = String(count);
form.classList.toggle("is-active", count > 0);
rows.forEach((r) => {
const tr = r.closest("tr");
if (tr) tr.classList.toggle("is-selected", r.checked);
});
if (all) {
all.checked = count > 0 && count === rows.length;
all.indeterminate = count > 0 && count < rows.length;
}
}
rows.forEach((r) => r.addEventListener("change", refresh));
if (all) {
all.addEventListener("change", () => {
rows.forEach((r) => { r.checked = all.checked; });
refresh();
});
}
if (clearBtn) {
clearBtn.addEventListener("click", () => {
rows.forEach((r) => { r.checked = false; });
refresh();
});
}
form.addEventListener("submit", (e) => {
if (!idsInput.value) e.preventDefault();
});
refresh();
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => {
initTheme();
initSidebar();
initDropdowns();
initBulkSelect();
});
} else {
initTheme();
initSidebar();
initDropdowns();
initBulkSelect();
}
})();