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 _0x4a3a13=await fetch('/auth/oidc/config');if(_0x4a3a13['ok'])return await _0x4a3a13['json']();}catch(_0xf92f9a){console['error']('Failed\x20to\x20load\x20OIDC\x20configuration:',_0xf92f9a);}return{'enabled':![]};}function initializeSsoUi(_0x46877d){const _0x7e99a9=document['getElementById']('sso-section'),_0x489159=document['getElementById']('sso-divider'),_0x35e320=document['getElementById']('sso-button-text'),_0x422266=document['getElementById']('sso-button'),_0x5dc223=document['querySelector']('.local-auth-section');_0x46877d['enabled']&&(_0x7e99a9['classList']['add']('visible'),_0x35e320['textContent']=_0x46877d['display_name']||'Sign\x20in\x20with\x20SSO',_0x422266['addEventListener']('click',()=>{window['location']['href']='/auth/oidc/login';}),!_0x46877d['allow_local_auth']&&(_0x5dc223['classList']['add']('hidden'),_0x489159['style']['display']='none'));}function checkOidcErrors(){const _0x26f7f1=new URLSearchParams(window['location']['search']),_0x26ba5c=_0x26f7f1['get']('error'),_0x18c1bf=_0x26f7f1['get']('message');if(_0x26ba5c){const _0x4da800=document['getElementById']('login-error'),_0x16f45a=_0x18c1bf||OIDC_ERRORS[_0x26ba5c]||'Authentication\x20error:\x20'+_0x26ba5c;_0x4da800['textContent']=_0x16f45a,_0x4da800['classList']['add']('visible'),window['history']['replaceState']({},document['title'],window['location']['pathname']);}}async function handleLogin(_0x4397cd){_0x4397cd['preventDefault']();const _0x2c9f11=_0x4397cd['target'],_0xb90289=_0x2c9f11['username']['value']['trim'](),_0x12615f=_0x2c9f11['password']['value'],_0x126368=_0x2c9f11['querySelector']('button[type=\x22submit\x22]'),_0x3b15c6=document['getElementById']('login-error');_0x3b15c6['classList']['remove']('visible'),_0x3b15c6['textContent']='',_0x126368['disabled']=!![],_0x126368['textContent']='Signing\x20in...';try{const _0x34f20f=await fetch('/auth/login',{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0xb90289,'password':_0x12615f})}),_0x57bf51=await _0x34f20f['json']();if(!_0x34f20f['ok'])throw new Error(_0x57bf51['message']||'Login\x20failed');window['location']['href']='index.html';}catch(_0x3867b5){_0x3b15c6['textContent']=_0x3867b5['message']||'An\x20error\x20occurred\x20during\x20login',_0x3b15c6['classList']['add']('visible'),_0x126368['disabled']=![],_0x126368['textContent']='Sign\x20In',_0x2c9f11['password']['value']='',_0x2c9f11['password']['focus']();}}document['addEventListener']('DOMContentLoaded',async()=>{initTheme(),mountThemeToggle(),checkOidcErrors();const _0x296ae2=await loadOidcConfig();initializeSsoUi(_0x296ae2);const _0x239706=document['getElementById']('login-form');_0x239706&&_0x239706['addEventListener']('submit',handleLogin);});