// Function to hide the chat widget if today is Monday
function hideChatWidget() {
    // Get the current day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
    var today = new Date().getDay();
    var schedlFlag = true;

    //Check if student service portal page
    var url = "" + top.location.href;
    var studentServiceURL = url.endsWith("student_services"); //Review

    //Check Schedule - Move to AJAX call
	if(studentServiceURL){

		var check = new GlideAjax('SUPortalAjaxUtil');
		check.addParam('sysparm_name', 'validateSchedule');
		//check.getXML(analyzeResponse);
		//console.log("response ===>>0 ");
		check.getXMLAnswer(analyzeResponse); 
	}
}

  function hideChatIcon(){
	var chatWidget = document.querySelector('.sp-ac-root.ng-scope.sp-ac-desktop'); // Combined class selector
	if (chatWidget) {
		chatWidget.style.display = 'none';
	}else {
		setTimeout(hideChatIcon, 5); 
	}
  }

  function analyzeResponse(response)
  {
	//console.log("response ===>>1 "+response);
	var answer = response;//.responseXML.documentElement.getAttribute("message");
	//console.log("response ===>>2 "+answer);
	if(answer == "no"){
		 // Select the div using the class name
        var chatWidget = document.querySelector('.sp-ac-root.ng-scope.sp-ac-desktop'); // Combined class selector
        if (chatWidget) {
            chatWidget.style.display = 'none';
        } else {
            setTimeout(hideChatIcon, 5); // Check again after 500ms if the element is not found
        }
	}
  }


// Add the function to the load event
document.addEventListener('DOMContentLoaded', hideChatWidget);