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 _0x3d115b=await fetch('/auth/oidc/config');if(_0x3d115b['ok'])return await _0x3d115b['json']();}catch(_0x3cd82d){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x3cd82d);}return{'enabled':![]};}function initializeSsoUi(_0x207643){const _0x4b4649=document['getElementById']('sso-section'),_0x39126c=document['getElementById']('sso-divider'),_0x5ddf4f=document['getElementById']('sso-button-text'),_0x3c2c8a=document['getElementById']('sso-button'),_0x571c1d=document['querySelector']('.local-auth-section');_0x207643['enabled']&&(_0x4b4649['classList']['add']('visible'),_0x5ddf4f['textContent']=_0x207643['display_name']||'Sign\x20in\x20with\x20SSO',_0x3c2c8a['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x207643['allow_local_auth']&&(_0x571c1d['classList']['add']('hidden'),_0x39126c['style']['display']='none'));}function checkOidcErrors(){const _0x4651ed=new URLSearchParams(window['location']['search']),_0x267df5=_0x4651ed['get']('error'),_0x5d4401=_0x4651ed['get']('message');if(_0x267df5){const _0xb9c33b=document['getElementById']('login-error'),_0x43557b=_0x5d4401||OIDC_ERRORS[_0x267df5]||'Authentication\x20error:\x20'+_0x267df5;_0xb9c33b['textContent']=_0x43557b,_0xb9c33b['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x1debf2){_0x1debf2['preventDefault']();const _0x13372a=_0x1debf2['target'],_0x126abd=_0x13372a['username']['value']['trim'](),_0x2916e0=_0x13372a['password']['value'],_0x2a03a3=_0x13372a['querySelector']('button[type=\x22submit\x22]'),_0x1597b7=document['getElementById']('login-error');_0x1597b7['classList']['remove']('visible'),_0x1597b7['textContent']='',_0x2a03a3['disabled']=!![],_0x2a03a3['textContent']='Signing\x20in...';try{const _0x282425=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x126abd,'password':_0x2916e0})}),_0x31c4de=await _0x282425['json']();if(!_0x282425['ok'])throw new Error(_0x31c4de['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x2f8988){_0x1597b7['textContent']=_0x2f8988['message']||'An\x20error\x20occurred\x20during\x20login',_0x1597b7['classList']['add']('visible'),_0x2a03a3['disabled']=![],_0x2a03a3['textContent']='Sign\x20In',_0x13372a['password']['value']='',_0x13372a['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x23b71b=await loadOidcConfig();initializeSsoUi(_0x23b71b);const _0x16aef7=document['getElementById']('login-form');_0x16aef7&&_0x16aef7['addEventListener']('submit',handleLogin);});