(function ($) {
	"use strict";

	/* ----------------------------------------------------------- */
	/*  Canvas Nav
	/* ----------------------------------------------------------- */
	jQuery(document).ready(function ($) {
		// Add span with icon to menu items that have children
		$('ul.main-responsive-menu li.menu-item-has-children > a').after('<span class="toggle-icon"><i class="ri-arrow-down-s-line"></i></span>');

		// Sub-menu toggling
		$('ul.main-responsive-menu li.menu-item-has-children span.toggle-icon').on('click', function () {
			$(this).next('ul.sub-menu').slideToggle();
			$(this).toggleClass('toggle');
		});
	});

	/* ----------------------------------------------------------- */
	/*  Back to top
	/* ----------------------------------------------------------- */
	$(window).scroll(function () {
		if ($(this).scrollTop() > 300) {
			$('.backto').fadeIn();
		} else {
			$('.backto').fadeOut();
		}
	});

	// scroll body to 0px on click
	$('.backto').on('click', function () {
		$('.backto').tooltip('hide');
		$('body,html').animate({
			scrollTop: 0
		}, 800);
		return false;
	});

	//Hide Loading Box (Preloader)
	function handlePreloader() {
		if ($('.theme-loader-wrap').length) {
			$('.theme-loader-wrap').delay(1000).fadeOut(500);
		}
	}

	if ($(".preloader-close").length) {
		$(".preloader-close").on("click", function () {
			$('.theme-loader-wrap').delay(200).fadeOut(500);
		})
	}

	/* ----------------------------------------------------------- */
	/*  Product Single Slider
	/* ----------------------------------------------------------- */
	$(document).ready(function () {
		jQuery('.woocommerce-product-gallery ol').slick({
			'type': true,
			'autoplay': false,
			'arrows': true,
			'prevArrow': '<div class="slide-arrow-left"><i class="ri-arrow-left-s-line"></i></div>',
			'nextArrow': '<div class="slide-arrow-right"><i class="ri-arrow-right-s-line"></i></div>',
			'dots': false,
			'fade': false,
			'infinite': true,
			'pauseOnHover': false,
			'slidesToShow': 3,
			'slidesToScroll': 1,
			'speed': 1500,

			responsive: [
				{
					breakpoint: 767,
					settings: {
						slidesToShow: 2,
						slidesToScroll: 2
					}
				}
			]
		});
	});

	/* ==========================================================================
	When document is loaded, do
	========================================================================== */

	$(window).on('load', function () {
		handlePreloader();
	});

	jQuery('.mainmenu ul.theme-main-menu').slicknav({
		allowParentLinks: true,
		prependTo: '.ethrik-responsive-menu',
		closedSymbol: "&#8594",
		openedSymbol: "&#8595",
	});

	/* ----------------------------------------------------------- */
	/*  Sticky Header
	/* ----------------------------------------------------------- */

	$(window).on('scroll', function (event) {
		var scroll = $(window).scrollTop();
		if (scroll < 86) {
			$(".stick-top").removeClass("sticky");
		} else {
			$(".stick-top").addClass("sticky");
		}
	});

	/* ----------------------------------------------------------- */
	/*  Dark Mode
	/* ----------------------------------------------------------- */

	$(document).ready(function () {

		/**
		* Light & Dark Mode jQuery Toggle Using localStorage
		*/

		// Check for saved 'switchMode' in localStorage
		let switchMode = localStorage.getItem('switchMode');

		// Get selector
		const switchModeToggle = $(' .mode-switcher ');

		// Dark mode function
		const enableDarkMode = function () {
			// Add the class to the body
			$('body').addClass('likhun-dark');
			// Update switchMode in localStorage
			localStorage.setItem('switchMode', 'enabled');
		}

		// Light mdoe function
		const disableDarkMode = function () {
			// Remove the class from the body
			$('body').removeClass('likhun-dark');
			// Update switchMode in localStorage value
			localStorage.setItem('switchMode', null);
		}

		// If the user already visited and enabled switchMode
		if (switchMode === 'enabled') {
			enableDarkMode();
			// Dark icon enabled
			$('.mode-icon-change').addClass('icofont-moon');
			$('.mode-icon-change').removeClass('icofont-sun-alt');
		} else {
			// Light icon enabled
			$('.mode-icon-change').addClass('icofont-sun-alt');
			$('.mode-icon-change').removeClass('icofont-moon');
		}

		// When someone clicks the button
		switchModeToggle.on('click', function () {
			// Change switch icon
			$('.mode-icon-change').toggleClass('icofont-sun-alt');
			$('.mode-icon-change').toggleClass('icofont-moon');

			// get their switchMode setting
			switchMode = localStorage.getItem('switchMode');

			// if it not current enabled, enable it
			if (switchMode !== 'enabled') {
				enableDarkMode();
				// if it has been enabled, turn it off  
			} else {
				disableDarkMode();
			}
		});



	}); // End load document

})(jQuery);