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 _0x2f9e43=await fetch('/auth/oidc/config');if(_0x2f9e43['ok'])return await _0x2f9e43['json']();}catch(_0x4c11a3){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x4c11a3);}return{'enabled':![]};}function initializeSsoUi(_0x1ccf7e){const _0x5cdd41=document['getElementById']('sso-section'),_0x2c850d=document['getElementById']('sso-divider'),_0x3f6d47=document['getElementById']('sso-button-text'),_0x3af923=document['getElementById']('sso-button'),_0x2e3d26=document['querySelector']('.local-auth-section');_0x1ccf7e['enabled']&&(_0x5cdd41['classList']['add']('visible'),_0x3f6d47['textContent']=_0x1ccf7e['display_name']||'Sign\x20in\x20with\x20SSO',_0x3af923['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x1ccf7e['allow_local_auth']&&(_0x2e3d26['classList']['add']('hidden'),_0x2c850d['style']['display']='none'));}function checkOidcErrors(){const _0x42033b=new URLSearchParams(window['location']['search']),_0x166c6c=_0x42033b['get']('error'),_0x19587f=_0x42033b['get']('message');if(_0x166c6c){const _0x4b5e18=document['getElementById']('login-error'),_0x817355=_0x19587f||OIDC_ERRORS[_0x166c6c]||'Authentication\x20error:\x20'+_0x166c6c;_0x4b5e18['textContent']=_0x817355,_0x4b5e18['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x3ebec6){_0x3ebec6['preventDefault']();const _0x3f34f4=_0x3ebec6['target'],_0x426ef4=_0x3f34f4['username']['value']['trim'](),_0x353fbf=_0x3f34f4['password']['value'],_0x514cbf=_0x3f34f4['querySelector']('button[type=\x22submit\x22]'),_0x220ed2=document['getElementById']('login-error');_0x220ed2['classList']['remove']('visible'),_0x220ed2['textContent']='',_0x514cbf['disabled']=!![],_0x514cbf['textContent']='Signing\x20in...';try{const _0x130049=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x426ef4,'password':_0x353fbf})}),_0x35da5e=await _0x130049['json']();if(!_0x130049['ok'])throw new Error(_0x35da5e['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x225ead){_0x220ed2['textContent']=_0x225ead['message']||'An\x20error\x20occurred\x20during\x20login',_0x220ed2['classList']['add']('visible'),_0x514cbf['disabled']=![],_0x514cbf['textContent']='Sign\x20In',_0x3f34f4['password']['value']='',_0x3f34f4['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x5079f1=await loadOidcConfig();initializeSsoUi(_0x5079f1);const _0x37fa76=document['getElementById']('login-form');_0x37fa76&&_0x37fa76['addEventListener']('submit',handleLogin);});