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 _0x1cfee9=await fetch('/auth/oidc/config');if(_0x1cfee9['ok'])return await _0x1cfee9['json']();}catch(_0x38fc6a){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x38fc6a);}return{'enabled':![]};}function initializeSsoUi(_0x44ea86){const _0x9f87fd=document['getElementById']('sso-section'),_0x2947ea=document['getElementById']('sso-divider'),_0x5643cf=document['getElementById']('sso-button-text'),_0x716bd7=document['getElementById']('sso-button'),_0x24049a=document['querySelector']('.local-auth-section');_0x44ea86['enabled']&&(_0x9f87fd['classList']['add']('visible'),_0x5643cf['textContent']=_0x44ea86['display_name']||'Sign\x20in\x20with\x20SSO',_0x716bd7['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x44ea86['allow_local_auth']&&(_0x24049a['classList']['add']('hidden'),_0x2947ea['style']['display']='none'));}function checkOidcErrors(){const _0x27990b=new URLSearchParams(window['location']['search']),_0x55b51e=_0x27990b['get']('error'),_0x126e02=_0x27990b['get']('message');if(_0x55b51e){const _0x3d0240=document['getElementById']('login-error'),_0x3e5bf0=_0x126e02||OIDC_ERRORS[_0x55b51e]||'Authentication\x20error:\x20'+_0x55b51e;_0x3d0240['textContent']=_0x3e5bf0,_0x3d0240['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x4120cb){_0x4120cb['preventDefault']();const _0x5366e5=_0x4120cb['target'],_0x4290fd=_0x5366e5['username']['value']['trim'](),_0x1eb26f=_0x5366e5['password']['value'],_0x53a13d=_0x5366e5['querySelector']('button[type=\x22submit\x22]'),_0x363903=document['getElementById']('login-error');_0x363903['classList']['remove']('visible'),_0x363903['textContent']='',_0x53a13d['disabled']=!![],_0x53a13d['textContent']='Signing\x20in...';try{const _0x10258c=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x4290fd,'password':_0x1eb26f})}),_0x33fd60=await _0x10258c['json']();if(!_0x10258c['ok'])throw new Error(_0x33fd60['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x4fc4cc){_0x363903['textContent']=_0x4fc4cc['message']||'An\x20error\x20occurred\x20during\x20login',_0x363903['classList']['add']('visible'),_0x53a13d['disabled']=![],_0x53a13d['textContent']='Sign\x20In',_0x5366e5['password']['value']='',_0x5366e5['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x3a8fd0=await loadOidcConfig();initializeSsoUi(_0x3a8fd0);const _0x573e60=document['getElementById']('login-form');_0x573e60&&_0x573e60['addEventListener']('submit',handleLogin);});