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 _0xfa52cb=await fetch('/auth/oidc/config');if(_0xfa52cb['ok'])return await _0xfa52cb['json']();}catch(_0x315c8b){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x315c8b);}return{'enabled':![]};}function initializeSsoUi(_0x5c3d02){const _0x3bb144=document['getElementById']('sso-section'),_0x23b2c2=document['getElementById']('sso-divider'),_0x14a45c=document['getElementById']('sso-button-text'),_0x4445ee=document['getElementById']('sso-button'),_0x91e0a2=document['querySelector']('.local-auth-section');_0x5c3d02['enabled']&&(_0x3bb144['classList']['add']('visible'),_0x14a45c['textContent']=_0x5c3d02['display_name']||'Sign\x20in\x20with\x20SSO',_0x4445ee['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x5c3d02['allow_local_auth']&&(_0x91e0a2['classList']['add']('hidden'),_0x23b2c2['style']['display']='none'));}function checkOidcErrors(){const _0x4ac95b=new URLSearchParams(window['location']['search']),_0x160288=_0x4ac95b['get']('error'),_0x495011=_0x4ac95b['get']('message');if(_0x160288){const _0x365fee=document['getElementById']('login-error'),_0x3da86f=_0x495011||OIDC_ERRORS[_0x160288]||'Authentication\x20error:\x20'+_0x160288;_0x365fee['textContent']=_0x3da86f,_0x365fee['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x23d715){_0x23d715['preventDefault']();const _0x133883=_0x23d715['target'],_0x215c84=_0x133883['username']['value']['trim'](),_0xb2a163=_0x133883['password']['value'],_0x42ffa7=_0x133883['querySelector']('button[type=\x22submit\x22]'),_0x1b264c=document['getElementById']('login-error');_0x1b264c['classList']['remove']('visible'),_0x1b264c['textContent']='',_0x42ffa7['disabled']=!![],_0x42ffa7['textContent']='Signing\x20in...';try{const _0xa35eb6=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x215c84,'password':_0xb2a163})}),_0x4c2aea=await _0xa35eb6['json']();if(!_0xa35eb6['ok'])throw new Error(_0x4c2aea['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x4feab5){_0x1b264c['textContent']=_0x4feab5['message']||'An\x20error\x20occurred\x20during\x20login',_0x1b264c['classList']['add']('visible'),_0x42ffa7['disabled']=![],_0x42ffa7['textContent']='Sign\x20In',_0x133883['password']['value']='',_0x133883['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x57d0b3=await loadOidcConfig();initializeSsoUi(_0x57d0b3);const _0x260d8b=document['getElementById']('login-form');_0x260d8b&&_0x260d8b['addEventListener']('submit',handleLogin);});