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(_0x3ca481,_0x228a69='error'){setupMessageEl['textContent']=_0x3ca481,setupMessageEl['className']='setup-message\x20'+_0x228a69+'\x20visible';}function hideMessage(){setupMessageEl['className']='setup-message';}function showError(_0x37ce52){loadingEl['classList']['remove']('visible'),setupContentEl['style']['display']='block',document['getElementById']('user-info')['style']['display']='none',setupFormEl['style']['display']='none',showMessage(_0x37ce52,'error');}async function validateToken(){if(!token){showError('No\x20token\x20provided.\x20Please\x20check\x20the\x20link\x20you\x20received.');return;}try{const _0x11eb3e=await fetch('/password/validate-token?token='+encodeURIComponent(token)),_0x44cc3c=await _0x11eb3e['json']();if(!_0x44cc3c['valid']){showError(_0x44cc3c['error']||'Invalid\x20or\x20expired\x20token.\x20Please\x20request\x20a\x20new\x20password\x20setup\x20link.');return;}loadingEl['classList']['remove']('visible'),setupContentEl['style']['display']='block',userUsernameEl['textContent']=_0x44cc3c['user']['username'],userNameEl['textContent']=_0x44cc3c['user']['name'];const _0x3fbfdc=document['querySelector']('.setup-header\x20p');_0x44cc3c['type']==='reset'?_0x3fbfdc['textContent']='Reset\x20your\x20password':_0x3fbfdc['textContent']='Create\x20a\x20secure\x20password\x20for\x20your\x20account',passwordInput['focus']();}catch(_0x2d5235){console['error']('Failed\x20to\x20validate\x20token:',_0x2d5235),showError('Failed\x20to\x20validate\x20token.\x20Please\x20try\x20again\x20or\x20contact\x20your\x20administrator.');}}async function handleSubmit(_0xc07f37){_0xc07f37['preventDefault'](),hideMessage();const _0x442b60=passwordInput['value'],_0x28ede1=confirmPasswordInput['value'];if(_0x442b60!==_0x28ede1){showMessage('Passwords\x20do\x20not\x20match','error'),confirmPasswordInput['focus']();return;}if(_0x442b60['length']<0x8){showMessage('Password\x20must\x20be\x20at\x20least\x208\x20characters\x20long','error'),passwordInput['focus']();return;}submitButton['disabled']=!![],submitButton['textContent']='Setting\x20password...';try{const _0x131596=await fetch('/password/setup',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'token':token,'password':_0x442b60})}),_0x5b0816=await _0x131596['json']();if(!_0x131596['ok'])throw new Error(_0x5b0816['error']||'Failed\x20to\x20set\x20password');showMessage('Password\x20set\x20successfully!\x20Redirecting\x20to\x20login...','success'),setupFormEl['reset'](),setTimeout(()=>{window['location']['href']='/login.html';},0x7d0);}catch(_0x61c568){console['error']('Failed\x20to\x20set\x20password:',_0x61c568),showMessage(_0x61c568['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();});