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 _0x37e8e7=await fetch('/auth/oidc/config');if(_0x37e8e7['ok'])return await _0x37e8e7['json']();}catch(_0x5ed60e){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0x5ed60e);}return{'enabled':![]};}function initializeSsoUi(_0x3dbb1b){const _0x1ad21d=document['getElementById']('sso-section'),_0x3cdf71=document['getElementById']('sso-divider'),_0x34971f=document['getElementById']('sso-button-text'),_0x5e623e=document['getElementById']('sso-button'),_0x49d044=document['querySelector']('.local-auth-section');_0x3dbb1b['enabled']&&(_0x1ad21d['classList']['add']('visible'),_0x34971f['textContent']=_0x3dbb1b['display_name']||'Sign\x20in\x20with\x20SSO',_0x5e623e['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x3dbb1b['allow_local_auth']&&(_0x49d044['classList']['add']('hidden'),_0x3cdf71['style']['display']='none'));}function checkOidcErrors(){const _0x313d28=new URLSearchParams(window['location']['search']),_0x4f06f2=_0x313d28['get']('error'),_0x5ce7e3=_0x313d28['get']('message');if(_0x4f06f2){const _0x4f3405=document['getElementById']('login-error'),_0x1d846b=_0x5ce7e3||OIDC_ERRORS[_0x4f06f2]||'Authentication\x20error:\x20'+_0x4f06f2;_0x4f3405['textContent']=_0x1d846b,_0x4f3405['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x5e1f5e){_0x5e1f5e['preventDefault']();const _0x55289f=_0x5e1f5e['target'],_0x58dd32=_0x55289f['username']['value']['trim'](),_0x5694f8=_0x55289f['password']['value'],_0x365882=_0x55289f['querySelector']('button[type=\x22submit\x22]'),_0xa19c73=document['getElementById']('login-error');_0xa19c73['classList']['remove']('visible'),_0xa19c73['textContent']='',_0x365882['disabled']=!![],_0x365882['textContent']='Signing\x20in...';try{const _0x5c1215=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x58dd32,'password':_0x5694f8})}),_0x4d1f5f=await _0x5c1215['json']();if(!_0x5c1215['ok'])throw new Error(_0x4d1f5f['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x6a65ac){_0xa19c73['textContent']=_0x6a65ac['message']||'An\x20error\x20occurred\x20during\x20login',_0xa19c73['classList']['add']('visible'),_0x365882['disabled']=![],_0x365882['textContent']='Sign\x20In',_0x55289f['password']['value']='',_0x55289f['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x1f0d3b=await loadOidcConfig();initializeSsoUi(_0x1f0d3b);const _0x1d248c=document['getElementById']('login-form');_0x1d248c&&_0x1d248c['addEventListener']('submit',handleLogin);});