(function () { 'use strict'; // เช็คสถานะ login - ถ้ายังไม่ login ให้ redirect ไปหน้า Login function checkLoginStatus() { const isLoggedIn = localStorage.getItem('isLoggedIn'); if (!isLoggedIn || isLoggedIn !== 'true') { window.location.href = typeof appPath === 'function' ? appPath('/Login/') : '/Login/'; return false; } return true; } // เช็ค login ก่อนทำอะไรต่อ if (!checkLoginStatus()) { return; // หยุดทำงานถ้ายังไม่ login } // ปุ่มต่างๆ function syncMainMenuScale() { var ui = document.querySelector('.menu-ui'); if (!ui) return; var vw = Math.max(1, window.innerWidth || 0); var vh = Math.max(1, window.innerHeight || 0); var scale = Math.min(1, vw / 1920, vh / 1080); ui.style.setProperty('--mm-scale', String(scale.toFixed(4))); } document.getElementById('btn-back')?.addEventListener('click', function () { window.location.href = typeof appPath === 'function' ? appPath('/Main-Lobby/') : '/Main-Lobby/'; }); document.getElementById('btn-create-room')?.addEventListener('click', function () { window.location.href = typeof appPath === 'function' ? appPath('/Create%20Room/') : '/Create%20Room/'; }); document.getElementById('btn-join')?.addEventListener('click', function () { window.location.href = typeof appPath === 'function' ? appPath('/Join%20Room/') : '/Join%20Room/'; }); document.getElementById('btn-exit-game')?.addEventListener('click', function () { if (confirm('คุณต้องการออกจากเกมหรือไม่?')) { localStorage.removeItem('isLoggedIn'); localStorage.removeItem('loginType'); window.location.href = typeof appPath === 'function' ? appPath('/Login/') : '/Login/'; } }); syncMainMenuScale(); window.addEventListener('resize', syncMainMenuScale); window.addEventListener('orientationchange', function () { setTimeout(syncMainMenuScale, 150); }); })();