import "./style.css"; import { fetchFollowUpQueue } from "./api"; import { renderAllBookings } from "./components/AllBookings"; import { renderDailyAgenda } from "./components/DailyAgenda"; import { renderFollowUpQueue } from "./components/FollowUpQueue"; type TabId = "queue" | "agenda" | "all"; class OperatorDashboardApp { private activeTab: TabId = "queue"; private container: HTMLElement; public get currentTab(): TabId { return this.activeTab; } constructor(container: HTMLElement) { this.container = container; this.init(); } private async init(): Promise { this.renderShell(); this.bindEvents(); await this.refreshTabBadge(); const hash = window.location.hash.replace("#", "") as TabId; const initialTab = hash === "agenda" || hash === "all" ? hash : "queue"; this.switchTab(initialTab); } private renderShell(): void { this.container.innerHTML = `

Armonía del Ser

Panel Operativo de Consultas y Agenda
Operador
Jasmin & Asistente
`; } private bindEvents(): void { const allTabButtons = this.container.querySelectorAll("[data-tab]"); allTabButtons.forEach((btn) => { btn.addEventListener("click", () => { const targetTab = btn.getAttribute("data-tab") as TabId; if (targetTab) { this.switchTab(targetTab); } }); }); window.addEventListener("hashchange", () => { const hash = window.location.hash.replace("#", "") as TabId; if (hash === "queue" || hash === "agenda" || hash === "all") { if (this.activeTab !== hash) { this.switchTab(hash); } } }); } private switchTab(tab: TabId): void { this.activeTab = tab; window.location.hash = tab; // Update both desktop and mobile active states const allTabButtons = this.container.querySelectorAll("[data-tab]"); allTabButtons.forEach((btn) => { const isCurrent = btn.getAttribute("data-tab") === tab; btn.classList.toggle("active", isCurrent); btn.setAttribute("aria-selected", isCurrent ? "true" : "false"); }); // Render tab view const contentEl = this.container.querySelector("#tab-content"); if (!contentEl) return; const onStateChange = async () => { await this.refreshTabBadge(); }; if (tab === "queue") { renderFollowUpQueue(contentEl, onStateChange); } else if (tab === "agenda") { renderDailyAgenda(contentEl, onStateChange); } else if (tab === "all") { renderAllBookings(contentEl); } } private async refreshTabBadge(): Promise { try { const queue = await fetchFollowUpQueue(); const count = queue.length; const badges = this.container.querySelectorAll( "#queue-badge, #queue-badge-mobile", ); badges.forEach((badge) => { if (count > 0) { badge.textContent = String(count); badge.classList.remove("hidden"); } else { badge.classList.add("hidden"); } }); } catch { // Ignore badge background fetch failure } } } const appRoot = document.getElementById("app"); if (appRoot) { new OperatorDashboardApp(appRoot); }