const BASE_USER_INFO_URL="/api/userinfo",LOGOUT_URL="/logout",USER_FAVORITE_FORUMS_URL="/api/userfavouriteforumsinfo",USER_BLOCKED_LIST_URL_MAIN="/api/userblockedlist",USER_HIBERNATION_URL="https://accounts.indiaforums.com/Manage/updatestatus";class App{static async init(){this.fetchUserInfo(),this.setupModules(),this.setupNavigation(),this.initializeUI()}static async fetchUserInfo(){try{const t=localStorage.getItem("checksum"),e=t?`/api/userinfo?checksum=${t}`:"/api/userinfo",s=await fetch(e);if(!s.ok)throw new Error(`Failed to fetch user info. Status: ${s.status}`);const a=await s.json();this.handleUserSession(a)}catch(t){console.error("Error fetching user info:",t),this.setBodyRoleClasses({isLoggedIn:!1})}}static async setupModules(){const{initDropDowns:t,initFlexDropdowns:e,initContentNavDropdowns:s}=await import("./dropDowns.min.js"),{initPageOverlay:a}=await import("./pageOverlay.min.js"),{initThemeManager:o}=await import("./theme-manager.min.js?hash=6b4f6e38"),{initReportModules:i}=await import("./reports.min.js?hash=b3870b47"),{enableTrendingNav:n}=await import("./entity.min.js?hash=175061b6");o(),a(),t(),e(),s(),i(),n()}static async setupNavigation(){const{initPageNavigation:t}=await import("./pageNavigation.min.js");t()}static initializeUI(){const t=document.getElementById("js-overlay");t&&t.addEventListener("click",(()=>{document.querySelectorAll(".show").forEach((t=>{t.classList.remove("show")})),t.classList.remove("show")}))}static async handleUserSession(t){if(this.setBodyRoleClasses(t),window.userInfo=t,window.dispatchEvent(new CustomEvent("userInfoReady",{detail:t})),t.isLoggedIn)switch(t.statusCode){case 0:alert("Your account is currently not active. You will be logged out. Please validate your email."),this.logout();break;case 1:this.updateUI(t);localStorage.getItem("userChecksum")!==t.userChecksum&&(this.fetchAndStoreData(USER_FAVORITE_FORUMS_URL,"favouriteForumData"),this.fetchAndStoreData("/api/userblockedlist","userBlockedListData"),localStorage.setItem("userChecksum",t.userChecksum));break;case 2:alert("Your account has been suspended."),this.logout();break;case 3:alert("Your account has been banned."),this.logout();break;case 4:const e=confirm("Your account is in Hibernation. Click OK to Re-Activate or CANCEL to Logout.");window.location.href=e?USER_HIBERNATION_URL:"/logout";break;default:console.warn("Unhandled user status code:",t.statusCode)}}static updateUI(t){t.isLoggedIn&&(this.updateUserAvatar(t.userAvatarUrl),this.updateElement("#js-inbox-count",t.unreadPmCount,"hidden"),this.updateElement("#js-notification-count",t.unreadNotificationCount,"hidden"))}static updateElement(t,e,s){const a=document.querySelector(t);a&&e&&(a.textContent=e,s&&a.classList.remove(s))}static updateUserAvatar(t){this.updateElement("#js-user-avatar",null);const e=document.querySelector("#js-user-avatar");e&&t&&(e.src=t)}static setBodyRoleClasses(t){const e=document.body;e.className="",t.isLoggedIn?(e.classList.add("role-loggedin"),t.isModerator&&e.classList.add("role-moderator"),t.isAdmin&&e.classList.add("role-admin")):e.classList.add("role-guest")}static async fetchAndStoreData(t,e){try{const s=await fetch(t),a=await s.json();localStorage.setItem(e,JSON.stringify(Array.isArray(a)?a:[a]))}catch(e){console.error(`Error fetching data from ${t}:`,e)}}static logout(){window.location.href="/logout"}static async handleUserInfoReady(t){window.userInfo=t.detail,this.cache&&"function"==typeof this.cache.clear&&this.cache.clear(),this.pending&&this.pending.length&&("function"==typeof this.processModules&&await this.processModules(this.pending),this.pending=[]);if(window.userInfo.isLoggedIn){const{default:t}=await import("./navbarDropdown.min.js?hash=e52344f7");t()}}}App.init(),window.userInfo?App.handleUserInfoReady({detail:window.userInfo}):window.addEventListener("userInfoReady",App.handleUserInfoReady.bind(App),{once:!0});
