import{initTheme,mountThemeToggle}from'./theme.js';initTheme();const urlParams=new URLSearchParams(window['location']['search']),token=urlParams['get']('token'),loadingEl=document['getElementById']('loading'),setupContentEl=document['getElementById']('setup-content'),setupFormEl=document['getElementById']('setup-form'),setupMessageEl=document['getElementById']('setup-message'),userUsernameEl=document['getElementById']('user-username'),userNameEl=document['getElementById']('user-name'),passwordInput=document['getElementById']('password'),confirmPasswordInput=document['getElementById']('confirm-password'),submitButton=setupFormEl?.['querySelector']('button[type=\x22submit\x22]');function showMessage(_0x26ff84,_0x5165c9='error'){setupMessageEl['textContent']=_0x26ff84,setupMessageEl['className']='setup-message\x20'+_0x5165c9+'\x20visible';}function hideMessage(){setupMessageEl['className']='setup-message';}function showError(_0x53f93d){loadingEl['classList']['remove']('visible'),setupContentEl['style']['display']='block',document['getElementById']('user-info')['style']['display']='none',setupFormEl['style']['display']='none',showMessage(_0x53f93d,'error');}async function validateToken(){if(!token){showError('No\x20token\x20provided.\x20Please\x20check\x20the\x20link\x20you\x20received.');return;}try{const _0x2c29ef=await fetch('/password/validate-token?token='+encodeURIComponent(token)),_0x153878=await _0x2c29ef['json']();if(!_0x153878['valid']){showError(_0x153878['error']||'Invalid\x20or\x20expired\x20token.\x20Please\x20request\x20a\x20new\x20password\x20setup\x20link.');return;}loadingEl['classList']['remove']('visible'),setupContentEl['style']['display']='block',userUsernameEl['textContent']=_0x153878['user']['username'],userNameEl['textContent']=_0x153878['user']['name'];const _0x47ee3b=document['querySelector']('.setup-header\x20p');_0x153878['type']==='reset'?_0x47ee3b['textContent']='Reset\x20your\x20password':_0x47ee3b['textContent']='Create\x20a\x20secure\x20password\x20for\x20your\x20account',passwordInput['focus']();}catch(_0x47df83){console['error']('Failed\x20to\x20validate\x20token:',_0x47df83),showError('Failed\x20to\x20validate\x20token.\x20Please\x20try\x20again\x20or\x20contact\x20your\x20administrator.');}}async function handleSubmit(_0x63657c){_0x63657c['preventDefault'](),hideMessage();const _0xeaaece=passwordInput['value'],_0x49a6fc=confirmPasswordInput['value'];if(_0xeaaece!==_0x49a6fc){showMessage('Passwords\x20do\x20not\x20match','error'),confirmPasswordInput['focus']();return;}if(_0xeaaece['length']<0x8){showMessage('Password\x20must\x20be\x20at\x20least\x208\x20characters\x20long','error'),passwordInput['focus']();return;}submitButton['disabled']=!![],submitButton['textContent']='Setting\x20password...';try{const _0x344f52=await fetch('/password/setup',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'token':token,'password':_0xeaaece})}),_0x503304=await _0x344f52['json']();if(!_0x344f52['ok'])throw new Error(_0x503304['error']||'Failed\x20to\x20set\x20password');showMessage('Password\x20set\x20successfully!\x20Redirecting\x20to\x20login...','success'),setupFormEl['reset'](),setTimeout(()=>{window['location']['href']='/login.html';},0x7d0);}catch(_0x47f6f9){console['error']('Failed\x20to\x20set\x20password:',_0x47f6f9),showMessage(_0x47f6f9['message']||'Failed\x20to\x20set\x20password.\x20Please\x20try\x20again.','error'),submitButton['disabled']=![],submitButton['textContent']='Set\x20Password';}}setupFormEl&&setupFormEl['addEventListener']('submit',handleSubmit);validateToken(),document['addEventListener']('DOMContentLoaded',()=>{mountThemeToggle();});