function renderSession() { const e = currentSession.isLoggedIn, t = currentSession.email || "", a = readProfileData(), o = a.companyName || "Ihr Unternehmen"; (loginForm.classList.toggle("is-hidden", e), dashboard.classList.toggle("is-hidden", !e), profileForm.classList.toggle("is-hidden", !e), e && ((dashboardTitle.textContent = `Willkommen, ${o}`), (sessionEmail.textContent = t ? `Angemeldet als ${t}` : ""), fillProfileForm(a))); } async function handleLoginSubmit(e) { if ( (e.preventDefault(), !validateForm(loginForm, "Bitte füllen Sie die Pflichtfelder aus.")) ) return; const t = loginEmail.value.trim(), a = loginPassword.value; let o; try { o = await withLoading( qs('button[type="submit"]', loginForm), "Login läuft", () => wpLogin(t, a), ); } catch (error) { const message = getErrorMessage(error, "Login fehlgeschlagen."); setStatus(loginStatus, message, "error"); showToast(message, "error"); return; } if (!o.success) return ( setStatus( loginStatus, getErrorMessage( o.error, "Login fehlgeschlagen. Bitte E-Mail und Passwort prüfen.", ), "error", ), void showToast( getErrorMessage(o.error, "Login fehlgeschlagen."), "error", ) ); ((currentSession = { isLoggedIn: true, email: t, profile: o.profile || {}, token: o.token || "", wpId: Number(o.user?.etx_aussteller_id || o.profile?.wpId) || 0, }), saveSession(), writeProfileData(currentSession.profile), setStatus(loginStatus, ""), (loginPassword.value = ""), renderSession(), showToast("Login erfolgreich.", "success")); } function handleLogoutClick() { ((currentSession = { isLoggedIn: false, email: "", profile: {}, token: "", wpId: 0, }), clearSession(), (wpBasicAuthHeader = ""), setStatus(profileStatus, ""), renderSession(), showToast("Sie wurden ausgeloggt.", "success")); } function updateDescCounter() { const e = document.getElementById("company-description"), t = document.getElementById("desc-counter"); if (!e || !t) return; ((t.textContent = e.value.length), (t.style.color = e.value.length >= 500 ? "#dc2626" : e.value.length > 450 ? "#d97706" : "")); } function validateLogoFile(e) { const t = 2 * 1024 * 1024, a = ["image/png", "image/jpeg", "image/webp"]; if (!e) return { valid: !1, error: "Keine Datei ausgewählt" }; if (!a.includes(e.type)) return { valid: !1, error: "Nur PNG, JPG oder WebP erlaubt" }; if (e.size > t) return { valid: !1, error: "Max. 2MB erlaubt" }; return new Promise((t) => { const a = new Image(); ((a.onload = function () { t( this.width < 300 || this.height < 300 ? { valid: !1, error: "Min. 300×300px erforderlich" } : { valid: !0 }, ); }), (a.onerror = () => t({ valid: !1, error: "Bild konnte nicht geladen werden" })), (a.src = URL.createObjectURL(e))); }); } function initProfileFormV2() { const e = document.getElementById("company-description"), t = document.getElementById("company-logo"); (e && (e.addEventListener("input", updateDescCounter), e.addEventListener("blur", updateDescCounter), updateDescCounter()), t && t.addEventListener("change", async (e) => { const a = e.target.files[0]; if (!a) return; const o = await validateLogoFile(a); if (!o.valid) return ( showToast(o.error, "error"), (t.value = ""), updateLogoPreview(selectedLogoDataUrl) ); const n = new FileReader(); ((n.onload = function (e) { ((selectedLogoDataUrl = String(e.target.result || "")), updateLogoPreview(selectedLogoDataUrl), showToast("Logo geladen", "success")); }), n.readAsDataURL(a)); })); } // Dashboard menu toggle const dashMenu = document.getElementById("dash-menu"); const dashLinks = dashMenu ? Array.from(dashMenu.querySelectorAll("a")) : []; const dashPanels = [ document.getElementById("profile-form"), document.getElementById("tickets-form"), document.getElementById("services-form"), document.getElementById("badges-form"), document.getElementById("requests-panel"), document.getElementById("documents-panel"), ].filter(Boolean); const isDashboardTarget = (hash) => dashPanels.some((panel) => hash === `#${panel.id}`); const hideDashboardPanels = () => { dashPanels.forEach((panel) => panel.classList.add("is-hidden")); dashLinks.forEach((link) => link.classList.remove("is-active")); }; const showDashboardPanel = (hash, shouldScroll = true) => { const target = document.getElementById(hash.slice(1)); if (!target) return; dashPanels.forEach((panel) => panel.classList.toggle("is-hidden", panel !== target), ); dashLinks.forEach((link) => link.classList.toggle("is-active", link.getAttribute("href") === hash), ); if (shouldScroll) target.scrollIntoView({ behavior: "smooth", block: "start" }); }; const originalRenderSession = renderSession; renderSession = function () { originalRenderSession(); const isLoggedIn = currentSession.isLoggedIn; if (dashMenu) dashMenu.classList.toggle("is-visible", isLoggedIn); if (isLoggedIn) { const targetHash = isDashboardTarget(window.location.hash) ? window.location.hash : "#profile-form"; showDashboardPanel(targetHash, false); } else { hideDashboardPanels(); } }; const originalHandleAnchorClick = handleAnchorClick; handleAnchorClick = function (e) { const hash = e.currentTarget.getAttribute("href"); if (hash && isDashboardTarget(hash)) { e.preventDefault(); history.pushState(null, "", hash); showDashboardPanel(hash); updateActiveNavLinks(); return; } originalHandleAnchorClick.call(this, e); };