document.addEventListener("DOMContentLoaded",function(){var e=Cookies.get("user_id"),t=Cookies.get("domain");e&&t&&t===window.location.hostname?window.location.href="dashboard.php":(Cookies.remove("user_id"),Cookies.remove("username"),Cookies.remove("name"),Cookies.remove("avatar"),Cookies.remove("domain"),Cookies.remove("user_type"));const s=document.forms.login_form,n=new URLSearchParams(window.location.search).get("redirect")||"dashboard.php";s.addEventListener("submit",function(e){e.preventDefault();var e=s.csrf_token.value,t=s.username.value,o=s.password.value,a=new FormData,e=(a.append("csrf_token",e),a.append("username",t),a.append("password",o),a.append("redirect",n),document.querySelector(".g-recaptcha"));if(e){t=grecaptcha.getResponse();if(!t)return(o=document.getElementById("error-message")).textContent="Please complete the reCAPTCHA.",void(o.style.display="block");a.append("g-recaptcha-response",t)}const r=new XMLHttpRequest;r.open("POST","./includes/login.php",!0),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.onreadystatechange=function(){var e,t;r.readyState===XMLHttpRequest.DONE&&(200===r.status?(e=JSON.parse(r.responseText)).success?((t=new Date).setTime(t.getTime()+108e5),Cookies.set("user_id",e.user_id,{expires:t,path:"/"}),Cookies.set("username",e.username,{expires:t,path:"/"}),Cookies.set("name",e.name,{expires:t,path:"/"}),Cookies.set("avatar",e.avatar,{expires:t,path:"/"}),Cookies.set("domain",e.domain,{expires:t,path:"/"}),Cookies.set("user_type",e.user_type,{expires:t,path:"/"}),window.location.href=n):((t=document.getElementById("error-message")).textContent=e.message,t.style.display="block"):console.error("An error occurred during the AJAX request."))},r.send(new URLSearchParams(a))})}),document.addEventListener("DOMContentLoaded",e=>{var t=document.querySelector(".g-recaptcha");t&&t.setAttribute("data-theme","dark")});