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 _0xb8a4a3=await fetch('/auth/oidc/config');if(_0xb8a4a3['ok'])return await _0xb8a4a3['json']();}catch(_0x1c967c){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x1c967c);}return{'enabled':![]};}function initializeSsoUi(_0x1f20ad){const _0x449101=document['getElementById']('sso-section'),_0x374f8d=document['getElementById']('sso-divider'),_0x1937af=document['getElementById']('sso-button-text'),_0x31ca94=document['getElementById']('sso-button'),_0x439c89=document['querySelector']('.local-auth-section');_0x1f20ad['enabled']&&(_0x449101['classList']['add']('visible'),_0x1937af['textContent']=_0x1f20ad['display_name']||'Sign\x20in\x20with\x20SSO',_0x31ca94['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x1f20ad['allow_local_auth']&&(_0x439c89['classList']['add']('hidden'),_0x374f8d['style']['display']='none'));}function checkOidcErrors(){const _0x191d81=new URLSearchParams(window['location']['search']),_0x33f0b7=_0x191d81['get']('error'),_0x1e7e4b=_0x191d81['get']('message');if(_0x33f0b7){const _0xa0fad1=document['getElementById']('login-error'),_0xf2c4db=_0x1e7e4b||OIDC_ERRORS[_0x33f0b7]||'Authentication\x20error:\x20'+_0x33f0b7;_0xa0fad1['textContent']=_0xf2c4db,_0xa0fad1['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x4c66b9){_0x4c66b9['preventDefault']();const _0x3657d6=_0x4c66b9['target'],_0x1ff652=_0x3657d6['username']['value']['trim'](),_0x38e15c=_0x3657d6['password']['value'],_0x4280d3=_0x3657d6['querySelector']('button[type=\x22submit\x22]'),_0x32bcda=document['getElementById']('login-error');_0x32bcda['classList']['remove']('visible'),_0x32bcda['textContent']='',_0x4280d3['disabled']=!![],_0x4280d3['textContent']='Signing\x20in...';try{const _0x37f7fb=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x1ff652,'password':_0x38e15c})}),_0x435135=await _0x37f7fb['json']();if(!_0x37f7fb['ok'])throw new Error(_0x435135['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x3e169e){_0x32bcda['textContent']=_0x3e169e['message']||'An\x20error\x20occurred\x20during\x20login',_0x32bcda['classList']['add']('visible'),_0x4280d3['disabled']=![],_0x4280d3['textContent']='Sign\x20In',_0x3657d6['password']['value']='',_0x3657d6['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x26b6fc=await loadOidcConfig();initializeSsoUi(_0x26b6fc);const _0x5d56b7=document['getElementById']('login-form');_0x5d56b7&&_0x5d56b7['addEventListener']('submit',handleLogin);});