'use strict';


function init() {
	/**
	 * add event listener on multiple elements
	 */

	const addEventOnElements = function (elements, eventType, callback) {
	  for (let i = 0, len = elements.length; i < len; i++) {
		elements[i].addEventListener(eventType, callback);
	  }
	}



	/**
	 * MOBILE NAVBAR TOGGLE
	 */

	const navbarHeader = document.querySelector("[data-navbar]");
	const navTogglers = document.querySelectorAll("[data-nav-toggler]");
	const overlay = document.querySelector("[data-overlay]");

	const toggleNav = function () {
	  navbarHeader.classList.toggle("active");
	  overlay.classList.toggle("active");
	}

	addEventOnElements(navTogglers, "click", toggleNav);



	/**
	 * active header when window scroll down to 100px
	 */

	const header = document.querySelector("[data-header]");

	const headerActive = function () {
	  if (window.scrollY > 100) {
		header.classList.add("active");
	  } else {
		header.classList.remove("active");
	  }
	}

	window.addEventListener("scroll", headerActive);
}

init();

function craftiAfterPageLoad() {
	//check if product page to add specific listners
	if(document.querySelector("[data-v-component-product]")) {
		productPage();
	}
	
	if(document.querySelector("[data-v-cart-page]")) {
		//cartPage();
	}
	//get navbar for sticky
	navbar = document.getElementsByClassName("navbar")[0];

	init();
}

window.VvvebTheme = window.VvvebTheme ?? {ajax:{}};
window.VvvebApp = window.VvvebApp ?? {};
VvvebTheme.ajax.afterLoad  = craftiAfterPageLoad;
