<?php include('bottom-bar.php'); ?>
<!-- jQuery (required for Owl Carousel and other plugins) -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<!-- Bootstrap 5.3.0 Bundle (includes Popper) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<!-- Owl Carousel -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>

<!-- Other Plugins -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/echo.js/1.7.3/echo.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.easing/1.4.1/jquery.easing.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.rateit/1.1.0/jquery.rateit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.3/js/lightbox.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>

<!-- Custom Scripts -->
<script src="assets/js/scripts.js?v=<?php echo time(); ?>"></script>
<script src="assets/js/bottom-nav.js?v=<?php echo time(); ?>"></script>


<!-- Custom Initialization Scripts -->
<script>
	$(document).ready(function () {
		// Bootstrap 5 Dropdown Toggle (using new API)
		$('.cnt-account .dropdown-menu .dropdown-item').on('click', function () {
			var $dropdown = $(this).closest('.dropdown');
			var bsDropdown = bootstrap.Dropdown.getInstance($dropdown.find('[data-bs-toggle="dropdown"]')[0]);

			// Manually hide the dropdown (Bootstrap 5)
			if (bsDropdown) {
				setTimeout(function () {
					bsDropdown.hide();
				}, 100);
			}
		});

		$('.cart-action, .dropdown-cart .dropdown-item').on('click', function () {
			var $dropdown = $(this).closest('.dropdown');
			var bsDropdown = bootstrap.Dropdown.getInstance($dropdown.find('[data-bs-toggle="dropdown"]')[0]);

			if (bsDropdown) {
				setTimeout(function () {
					bsDropdown.hide();
				}, 100);
			}
		});

		// Main Carousel
		$('#owl-main').owlCarousel({
			items: 1,
			loop: true,
			margin: 0,
			nav: true,
			dots: true,
			autoplay: true,
			autoplayTimeout: 5000,
			autoplayHoverPause: true,
			navText: [
				'<span class="owl-nav-prev">&lt;</span>',
				'<span class="owl-nav-next">&gt;</span>'
			]
		});

		// Hero Carousel
		$('#hero-carousel').owlCarousel({
			items: 1,
			loop: true,
			margin: 0,
			nav: true,
			dots: true,
			autoplay: true,
			autoplayTimeout: 5000,
			autoplayHoverPause: true,
			navText: [
				'<i class="fa fa-chevron-left"></i>',
				'<i class="fa fa-chevron-right"></i>'
			]
		});

		// Product Carousels
		$('.home-owl-carousel').each(function () {
			var carousel = $(this);
			var itemCount = carousel.data('item') || 4;

			carousel.owlCarousel({
				loop: true,
				margin: 10,
				nav: true,
				dots: false,
				autoplay: false,
				navText: [
					'<i class="fa fa-chevron-left"></i>',
					'<i class="fa fa-chevron-right"></i>'
				],
				responsive: {
					0: {
						items: 2
					},
					576: {
						items: 3
					},
					768: {
						items: 4
					},
					992: {
						items: itemCount
					}
				}
			});
		});

		// Initialize WOW.js for animations
		if (typeof WOW !== 'undefined') {
			new WOW().init();
		}

		// Initialize Bootstrap tooltips
		var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
		tooltipTriggerList.map(function (tooltipTriggerEl) {
			return new bootstrap.Tooltip(tooltipTriggerEl);
		});

		// Scroll to Top Button
		var scrollToTopBtn = $('<button class="scroll-to-top"><i class="fa fa-chevron-up"></i></button>');
		$('body').append(scrollToTopBtn);

		$(window).scroll(function () {
			if ($(this).scrollTop() > 300) {
				scrollToTopBtn.addClass('visible');
			} else {
				scrollToTopBtn.removeClass('visible');
			}
		});

		scrollToTopBtn.click(function () {
			$('html, body').animate({ scrollTop: 0 }, 600);
			return false;
		});
	});
</script>
