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