// Scroll to Top
window.onscroll = function() {
  const ai_machine_learning_button = document.querySelector('.scroll-top-box');
  if (ai_machine_learning_button) {
    if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
      ai_machine_learning_button.style.display = "block";
    } else {
      ai_machine_learning_button.style.display = "none";
    }
  }
};

const scrollTopLink = document.querySelector('.scroll-top-box a');
if (scrollTopLink) {
  scrollTopLink.onclick = function(event) {
    event.preventDefault();
    window.scrollTo({ top: 0, behavior: 'smooth' });
  };
}

// header sidebar Toggle
document.addEventListener("DOMContentLoaded", () => {
  const ai_machine_learning_toggle = document.querySelector(".header-info-btn a"),
        ai_machine_learning_info = document.querySelector(".header-info"),
        ai_machine_learning_close = document.querySelector(".info-close-btn a");

  if (!ai_machine_learning_toggle || !ai_machine_learning_info) return;

  ai_machine_learning_toggle.onclick = () => (ai_machine_learning_info.classList.add("active"), document.body.classList.add("header-info-open"));
  ai_machine_learning_close && (ai_machine_learning_close.onclick = () => (ai_machine_learning_info.classList.remove("active"), document.body.classList.remove("header-info-open")));

  document.addEventListener("click", e => {
    if (document.body.classList.contains("header-info-open") &&
        !ai_machine_learning_info.contains(e.target) && !ai_machine_learning_toggle.contains(e.target)) {
      ai_machine_learning_info.classList.remove("active");
      document.body.classList.remove("header-info-open");
    }
  });
});

document.addEventListener("DOMContentLoaded", () => {
  const ai_machine_learning_toggleBtn = document.querySelector(".header-info-btn a"); // open button
  const ai_machine_learning_infoBox = document.querySelector(".header-info"); // info box
  const ai_machine_learning_closeBtn = document.querySelector(".info-close-btn a"); // close button

  if (!ai_machine_learning_toggleBtn || !ai_machine_learning_infoBox || !ai_machine_learning_closeBtn) return;

  // OPEN the info box
  ai_machine_learning_toggleBtn.addEventListener("click", () => {
    ai_machine_learning_infoBox.classList.add("active");
    document.body.classList.add("header-info-active");

    // Optional: move keyboard focus inside
    const firstFocusable = ai_machine_learning_infoBox.querySelector(
      'a, button, input, textarea, select, [tabindex]:not([tabindex="-1"])'
    );
    if (firstFocusable) firstFocusable.focus();
  });

  // CLOSE the info box (when clicking the close icon)
  ai_machine_learning_closeBtn.addEventListener("click", () => {
    ai_machine_learning_infoBox.classList.remove("active");
    document.body.classList.remove("header-info-active");
    ai_machine_learning_toggleBtn.focus(); // return focus to the button
  });

  // Trap focus inside when active
  document.addEventListener("keydown", (e) => {
    if (!ai_machine_learning_infoBox.classList.contains("active")) return;

    const focusable = ai_machine_learning_infoBox.querySelectorAll(
      'a, button, input, textarea, select, [tabindex]:not([tabindex="-1"])'
    );
    const first = focusable[0];
    const last = focusable[focusable.length - 1];

    if (e.key === "Tab") {
      if (e.shiftKey && document.activeElement === first) {
        e.preventDefault();
        last.focus();
      } else if (!e.shiftKey && document.activeElement === last) {
        e.preventDefault();
        first.focus();
      }
    }

    // ESC key also closes the box
    if (e.key === "Escape") {
      ai_machine_learning_closeBtn.click();
    }
  });
});

// banner
jQuery(document).ready(function ($) {
    if ($.fn.owlCarousel) {
        $('.project-sec .owl-carousel').owlCarousel({
            loop: true,
            margin: 30,
            nav: false,
            dots: false,
            rtl: false,
            autoplay: false,
            responsive: {
                0: {
                    items: 1
                },
                600: {
                    items: 1
                },
                768: {
                    items: 2
                },
                1200: {
                    items: 3
                }
            }
        });
    } else {
        console.log('Owl Carousel not loaded');
    }
});