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 _0xb1618c=await fetch('/auth/oidc/config');if(_0xb1618c['ok'])return await _0xb1618c['json']();}catch(_0x1f490d){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x1f490d);}return{'enabled':![]};}function initializeSsoUi(_0x433ce3){const _0x3a0430=document['getElementById']('sso-section'),_0x56e854=document['getElementById']('sso-divider'),_0x35e50c=document['getElementById']('sso-button-text'),_0x1ca490=document['getElementById']('sso-button'),_0x26bc0d=document['querySelector']('.local-auth-section');_0x433ce3['enabled']&&(_0x3a0430['classList']['add']('visible'),_0x35e50c['textContent']=_0x433ce3['display_name']||'Sign\x20in\x20with\x20SSO',_0x1ca490['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x433ce3['allow_local_auth']&&(_0x26bc0d['classList']['add']('hidden'),_0x56e854['style']['display']='none'));}function checkOidcErrors(){const _0x66ac3d=new URLSearchParams(window['location']['search']),_0x4a36f9=_0x66ac3d['get']('error'),_0x57c133=_0x66ac3d['get']('message');if(_0x4a36f9){const _0x36a1ee=document['getElementById']('login-error'),_0x2cb507=_0x57c133||OIDC_ERRORS[_0x4a36f9]||'Authentication\x20error:\x20'+_0x4a36f9;_0x36a1ee['textContent']=_0x2cb507,_0x36a1ee['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x44db28){_0x44db28['preventDefault']();const _0x39945b=_0x44db28['target'],_0xaee80b=_0x39945b['username']['value']['trim'](),_0x55d02b=_0x39945b['password']['value'],_0x2f268a=_0x39945b['querySelector']('button[type=\x22submit\x22]'),_0x4162d8=document['getElementById']('login-error');_0x4162d8['classList']['remove']('visible'),_0x4162d8['textContent']='',_0x2f268a['disabled']=!![],_0x2f268a['textContent']='Signing\x20in...';try{const _0x1bd82a=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0xaee80b,'password':_0x55d02b})}),_0x15342a=await _0x1bd82a['json']();if(!_0x1bd82a['ok'])throw new Error(_0x15342a['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x26f91d){_0x4162d8['textContent']=_0x26f91d['message']||'An\x20error\x20occurred\x20during\x20login',_0x4162d8['classList']['add']('visible'),_0x2f268a['disabled']=![],_0x2f268a['textContent']='Sign\x20In',_0x39945b['password']['value']='',_0x39945b['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x14a223=await loadOidcConfig();initializeSsoUi(_0x14a223);const _0x3d0d12=document['getElementById']('login-form');_0x3d0d12&&_0x3d0d12['addEventListener']('submit',handleLogin);});