// // show
// const subNav = document.getElementsByClassName('sub-ul-list');
// const navLink = document.getElementsByClassName('nav-link');
// console.log(subNav);
// console.log(navLink);

// navLink.addEventListener("mouseover", () => {
//     if()
// });

const loader = document.getElementById("loader");

window.addEventListener("load", () => {
    loader.style.display = 'none';
});

// NavBar
const navList = document.getElementById('nav-list-container');
const toggleNav = () => {
    navList.classList.toggle('hidden');
}

const aboutUsList = document.getElementById('aboutUsList');
const aboutUsText = document.getElementById('aboutUsText');
const aboutUsIcon = document.getElementById('aboutUsIcon');
const toggleAboutUs = () => {
    aboutUsList.classList.toggle('hidden');
    aboutUsText.classList.toggle('active-toggle');
    aboutUsIcon.classList.toggle('nav-active-icon');
}

const eventsList = document.getElementById('eventsList');
const eventsText = document.getElementById('eventsText');
const eventsIcon = document.getElementById('eventsIcon');
const toggleEvents = () => {
    eventsList.classList.toggle('hidden');
    eventsText.classList.toggle('active-toggle');
    eventsIcon.classList.toggle('nav-active-icon');
}

const highlightList = document.getElementById('highlightList');
const highlightText = document.getElementById('highlightText');
const highlightIcon = document.getElementById('highlightIcon');
const toggleHighlights = () => {
    highlightList.classList.toggle('hidden');
    highlightText.classList.toggle('active-toggle');
    highlightIcon.classList.toggle('nav-active-icon');
}

// Career
const carrierContainer = document.getElementById('carrier-form');
const carrierToggle = () => {
    carrierContainer.classList.add('carrier-form-container');
    carrierContainer.classList.add('p-md-5');
    carrierContainer.classList.toggle('carrier-form-in');
    carrierContainer.classList.toggle('carrier-form-out');
}

// Statics
function animateValue(obj, start, end, duration) {
    let startTimestamp = null;
    const step = (timestamp) => {
        if (!startTimestamp) startTimestamp = timestamp;
        const progress = Math.min((timestamp - startTimestamp) / duration, 1);
        obj.innerHTML = Math.floor(progress * (end - start) + start);
        if (progress < 1) {
            window.requestAnimationFrame(step);
        }
    };
    window.requestAnimationFrame(step);
}

const statics = document.getElementById("staticsNumber");
const partners = document.getElementById("partnersNumber");
const companies = document.getElementById("companiesAttendedNumber");
const speakers = document.getElementById("speakersAttendedNumber");
const delegates = document.getElementById("delegatesAttendedNumber");
const noOfPartners = document.getElementById("sponsorsContentContainer");

var counter = 0;

window.onload = () => {
    const observerIn = new IntersectionObserver((e) => {
        e.forEach((e) => {
            if(e.isIntersecting){
                if(counter === 0){
                    counter = counter + 1;
                    animateValue(statics, 0, 80, 1000);
                    animateValue(partners, 0, noOfPartners.children.length, 1000);
                    animateValue(companies, 0, 6003, 1000);
                    animateValue(speakers, 0, 657, 1000);
                    animateValue(delegates, 0, 8385, 1000);
                }
            }
        })
    });
    const staticsContainer = document.querySelectorAll('.statics-text');
    staticsContainer.forEach((e) => observerIn.observe(e));
}

function setConferenceSpeed(){
    const conferenceContentContainer = document.querySelectorAll('.conference-content-container');
    if(conferenceContentContainer){
        for(var i = 0; i < conferenceContentContainer.length; i++){
            var count = 1;
            for(var j = 0; j < conferenceContentContainer[i].children.length ; j++){
                if(count == 6){
                    count = 1
                }
                count++;
                var speed = count * 100;
                conferenceContentContainer[i].children[j].setAttribute("data-aos-delay" , speed);
            }
        }
    }
    else{
        return 0;
    }
}

setConferenceSpeed();