const menu = document.createElement("div"); menu.id = "command-menu"; menu.className = "fixed z-50 w-48 hidden flex-col gap-1.5 rounded-xl border border-slate-800 bg-slate-900/90 p-3 shadow-xl backdrop-blur overflow-y-auto overscroll-contain"; menu.style.maxHeight = "min(70vh, 520px)"; menu.innerHTML = `
`; document.body.appendChild(menu); const modal = document.createElement("div"); modal.className = "modal fixed inset-0 z-40 hidden items-center justify-center bg-black/80 backdrop-blur"; modal.innerHTML = `
preview
`; document.body.appendChild(modal); const modalImg = modal.querySelector("#modal-img"); export function openMenu(clientId, x, y, setContext, options = {}) { if (setContext) setContext(clientId); const removeBtn = menu.querySelector('[data-action="remove-dashboard"]'); if (removeBtn) { const isOnline = options.isOnline === true; removeBtn.classList.toggle("hidden", isOnline); } menu.classList.remove("hidden"); const menuWidth = 192; const menuHeight = menu.offsetHeight || 400; const viewportWidth = window.innerWidth; const viewportHeight = window.innerHeight; let left = x; if (left + menuWidth > viewportWidth - 10) { left = viewportWidth - menuWidth - 10; } if (left < 10) left = 10; let top = y; if (top + menuHeight > viewportHeight - 10) { top = viewportHeight - menuHeight - 10; } if (top < 10) top = 10; menu.style.left = `${left}px`; menu.style.top = `${top}px`; } export function closeMenu(clearContext) { menu.classList.add("hidden"); if (clearContext) clearContext(); } export function openModal(src) { if (!src) return; modalImg.src = ""; setTimeout(() => { modalImg.src = src; modal.classList.remove("hidden"); modal.classList.add("flex"); }, 10); } export function closeModal() { modal.classList.remove("flex"); modal.classList.add("hidden"); } export function wireModalClose() { modal.addEventListener("click", closeModal); window.addEventListener("keydown", (e) => { if (e.key === "Escape") { closeModal(); closeMenu(); } }); } export { menu, modal };