import{initTheme,mountThemeToggle}from'./theme.js';const OIDC_ERRORS={'oidc_init_failed':'Failed\x20to\x20connect\x20to\x20the\x20identity\x20provider.\x20Please\x20try\x20again.','oidc_not_configured':'Single\x20sign-on\x20is\x20not\x20configured.\x20Please\x20use\x20local\x20login.','oidc_error':'Authentication\x20was\x20cancelled\x20or\x20failed.','oidc_invalid_callback':'Invalid\x20authentication\x20response.\x20Please\x20try\x20again.','oidc_no_email':'Your\x20identity\x20provider\x20did\x20not\x20provide\x20an\x20email\x20address.\x20Please\x20contact\x20your\x20administrator.','oidc_user_not_found':'Your\x20account\x20is\x20not\x20authorized\x20to\x20access\x20this\x20application.\x20Please\x20contact\x20your\x20administrator.','oidc_invalid_state':'Authentication\x20session\x20expired.\x20Please\x20try\x20again.','oidc_session_expired':'Authentication\x20session\x20expired.\x20Please\x20try\x20again.','oidc_callback_failed':'Authentication\x20failed.\x20Please\x20try\x20again.','session_failed':'Failed\x20to\x20create\x20session.\x20Please\x20try\x20again.'};async function loadOidcConfig(){try{const _0x3a0412=await fetch('/auth/oidc/config');if(_0x3a0412['ok'])return await _0x3a0412['json']();}catch(_0x36897e){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x36897e);}return{'enabled':![]};}function initializeSsoUi(_0x55f720){const _0x483ea5=document['getElementById']('sso-section'),_0x26a9b4=document['getElementById']('sso-divider'),_0x4680a3=document['getElementById']('sso-button-text'),_0x216f1c=document['getElementById']('sso-button'),_0x393403=document['querySelector']('.local-auth-section');_0x55f720['enabled']&&(_0x483ea5['classList']['add']('visible'),_0x4680a3['textContent']=_0x55f720['display_name']||'Sign\x20in\x20with\x20SSO',_0x216f1c['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x55f720['allow_local_auth']&&(_0x393403['classList']['add']('hidden'),_0x26a9b4['style']['display']='none'));}function checkOidcErrors(){const _0x952624=new URLSearchParams(window['location']['search']),_0x2f2d48=_0x952624['get']('error'),_0x4855a7=_0x952624['get']('message');if(_0x2f2d48){const _0xdcacce=document['getElementById']('login-error'),_0x4b64c8=_0x4855a7||OIDC_ERRORS[_0x2f2d48]||'Authentication\x20error:\x20'+_0x2f2d48;_0xdcacce['textContent']=_0x4b64c8,_0xdcacce['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x1d907b){_0x1d907b['preventDefault']();const _0x34ca2c=_0x1d907b['target'],_0x5c124a=_0x34ca2c['username']['value']['trim'](),_0xb75a94=_0x34ca2c['password']['value'],_0x59c4bd=_0x34ca2c['querySelector']('button[type=\x22submit\x22]'),_0x3aee04=document['getElementById']('login-error');_0x3aee04['classList']['remove']('visible'),_0x3aee04['textContent']='',_0x59c4bd['disabled']=!![],_0x59c4bd['textContent']='Signing\x20in...';try{const _0xfae72b=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x5c124a,'password':_0xb75a94})}),_0x56dfd6=await _0xfae72b['json']();if(!_0xfae72b['ok'])throw new Error(_0x56dfd6['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x4a5a89){_0x3aee04['textContent']=_0x4a5a89['message']||'An\x20error\x20occurred\x20during\x20login',_0x3aee04['classList']['add']('visible'),_0x59c4bd['disabled']=![],_0x59c4bd['textContent']='Sign\x20In',_0x34ca2c['password']['value']='',_0x34ca2c['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x9bd9c3=await loadOidcConfig();initializeSsoUi(_0x9bd9c3);const _0xa26368=document['getElementById']('login-form');_0xa26368&&_0xa26368['addEventListener']('submit',handleLogin);});