/* ==========================================================================
M GALA — Public site shared behavior (header/footer, voting, sharing, etc.)
========================================================================== */
(function () {
"use strict";
var Store = window.MGala.Store;
/* ---------- initials-avatar fallback for broken photo URLs ---------- */
function initialsAvatar(name) {
var initials = (name || "?").split(" ").filter(Boolean).slice(0, 2).map(function (s) { return s[0]; }).join("").toUpperCase();
var svg = '';
return "data:image/svg+xml;base64," + btoa(svg);
}
window.MGala.attachImgFallback = function (img, name) {
img.addEventListener("error", function onErr() {
img.removeEventListener("error", onErr);
img.src = initialsAvatar(name);
});
};
/* ---------------------------- toast ---------------------------- */
var toastTimer;
window.MGala.toast = function (msg, icon) {
var el = document.getElementById("mg-toast");
if (!el) {
el = document.createElement("div");
el.id = "mg-toast";
el.className = "toast";
document.body.appendChild(el);
}
el.innerHTML = '' + msg + "";
el.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(function () { el.classList.remove("show"); }, 3200);
};
/* ---------------------------- header / footer ---------------------------- */
var CATS_CACHE = null;
function cats() { return CATS_CACHE || (CATS_CACHE = Store.getCategories()); }
window.MGala.renderHeader = function (root, active) {
var host = document.getElementById(root || "site-header");
if (!host) return;
host.innerHTML =
'