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 _0x2d2f73=await fetch('/auth/oidc/config');if(_0x2d2f73['ok'])return await _0x2d2f73['json']();}catch(_0x371037){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x371037);}return{'enabled':![]};}function initializeSsoUi(_0x25a0f1){const _0x3b026e=document['getElementById']('sso-section'),_0x22934c=document['getElementById']('sso-divider'),_0x44ea56=document['getElementById']('sso-button-text'),_0x279a9e=document['getElementById']('sso-button'),_0x37f60c=document['querySelector']('.local-auth-section');_0x25a0f1['enabled']&&(_0x3b026e['classList']['add']('visible'),_0x44ea56['textContent']=_0x25a0f1['display_name']||'Sign\x20in\x20with\x20SSO',_0x279a9e['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x25a0f1['allow_local_auth']&&(_0x37f60c['classList']['add']('hidden'),_0x22934c['style']['display']='none'));}function checkOidcErrors(){const _0x3937f0=new URLSearchParams(window['location']['search']),_0x371d19=_0x3937f0['get']('error'),_0x426d28=_0x3937f0['get']('message');if(_0x371d19){const _0x15144a=document['getElementById']('login-error'),_0x189957=_0x426d28||OIDC_ERRORS[_0x371d19]||'Authentication\x20error:\x20'+_0x371d19;_0x15144a['textContent']=_0x189957,_0x15144a['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x3bda61){_0x3bda61['preventDefault']();const _0x2ba6a3=_0x3bda61['target'],_0x4f9f57=_0x2ba6a3['username']['value']['trim'](),_0xbd9db4=_0x2ba6a3['password']['value'],_0x3608f8=_0x2ba6a3['querySelector']('button[type=\x22submit\x22]'),_0x2555c6=document['getElementById']('login-error');_0x2555c6['classList']['remove']('visible'),_0x2555c6['textContent']='',_0x3608f8['disabled']=!![],_0x3608f8['textContent']='Signing\x20in...';try{const _0x1a54c0=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x4f9f57,'password':_0xbd9db4})}),_0x2ea325=await _0x1a54c0['json']();if(!_0x1a54c0['ok'])throw new Error(_0x2ea325['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x5d7198){_0x2555c6['textContent']=_0x5d7198['message']||'An\x20error\x20occurred\x20during\x20login',_0x2555c6['classList']['add']('visible'),_0x3608f8['disabled']=![],_0x3608f8['textContent']='Sign\x20In',_0x2ba6a3['password']['value']='',_0x2ba6a3['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x2b8a99=await loadOidcConfig();initializeSsoUi(_0x2b8a99);const _0x3a79fa=document['getElementById']('login-form');_0x3a79fa&&_0x3a79fa['addEventListener']('submit',handleLogin);});