\n \n \n `,t.appendChild(a)}));"true"!==n&&document.querySelectorAll(".edit-btn, .delete-btn").forEach((e=>{e.style.display="none"})),document.querySelectorAll(".delete-btn").forEach((t=>{t.addEventListener("click",(function(){const t=this.getAttribute("data-index");e.splice(t,1),localStorage.setItem("upcomingClasses",JSON.stringify(e)),displayUpcomingClasses()}))})),document.querySelectorAll(".edit-btn").forEach((e=>{e.addEventListener("click",(function(){const e=this.closest(".card");e.querySelectorAll("input").forEach((e=>e.disabled=!1)),this.style.display="none",e.querySelector(".save-btn").style.display="block"}))})),document.querySelectorAll(".save-btn").forEach((t=>{t.addEventListener("click",(function(){const t=this.getAttribute("data-index"),n=this.closest(".card"),a=n.querySelector(".class-name-input").value,s=n.querySelector(".subject-input").value,l=n.querySelector(".faculty-input").value,o=n.querySelector(".room-input").value.split(" ")[0],i=n.querySelector(".date-input").value,c=n.querySelectorAll(".time-input")[0].value,r=n.querySelectorAll(".time-input")[1].value;if(!(a&&s&&l&&o&&i&&c&&r))return void alert("Please enter all class details!");const d=new Date(`${i}T${c}`),m=new Date(`${i}T${r}`);if(d>=m)return void alert("The start time must be earlier than the end time.");if(e.some(((e,n)=>{if(n!==parseInt(t)&&e.room===o&&e.dateTime===i){const t=new Date(`${e.dateTime}T${e.fromTime}`),n=new Date(`${e.dateTime}T${e.toTime}`);return dt}return!1})))return void alert("The room is already booked for this date and time.");e.some(((e,n)=>{if(n!==parseInt(t)&&e.faculty===l&&e.dateTime===i){const t=new Date(`${e.dateTime}T${e.fromTime}`),n=new Date(`${e.dateTime}T${e.toTime}`);return dt}return!1}))?alert("The faculty is already assigned to another class at this time."):(e[t]={className:a,subject:s,faculty:l,room:o,dateTime:i,fromTime:c,toTime:r},localStorage.setItem("upcomingClasses",JSON.stringify(e)),n.querySelectorAll("input").forEach((e=>e.disabled=!0)),this.style.display="none",n.querySelector(".edit-btn").style.display="block",displayVacantRooms())}))})),displayVacantRooms()}function isRoomAvailable(e,t,n){return!(JSON.parse(localStorage.getItem("upcomingClasses"))||[]).filter(((e,t)=>t!==n)).some((n=>n.room===e&&n.dateTime===t))}function logout(){localStorage.removeItem("isLoggedIn"),window.location.href="index.html"}window.onload=function(){const e=localStorage.getItem("isLoggedIn"),t=document.getElementById("homeLink"),n=document.getElementById("loginLink");"true"===e?(t.classList.remove("d-none"),n.textContent="Logout",n.href="javascript:logout()"):(t.classList.add("d-none"),n.textContent="Login",n.href="login.html"),displayUpcomingClasses()}