if ($(window).width() < 1020) {}


$(window).on("load", function () {

    "use strict";
    /* ===================================
            Loading Timeout
     ====================================== */


    $('.side-menu').removeClass('hidden');


    setTimeout(function () {
        $(".loader").fadeOut("slow");
    }, 1000);


});

/* ===================================
       Fixed Navbar 
   ====================================== */
$(function () {
    $(document).scroll(function () {
        var $nav = $(".navbar-fixed-top");
        $nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
    });
});

/* ===================================
            Cube Portfolio
    ======================================*/

$('#js-grid-mosaic-flat').cubeportfolio({
    filters: '#js-filters-mosaic-flat',
    layoutMode: 'mosaic',
    sortByDimension: true,
    mediaQueries: [{
        width: 1500,
        cols: 6,
    }, {
        width: 1100,
        cols: 4,
    }, {
        width: 800,
        cols: 3,
    }, {
        width: 480,
        cols: 1,
        options: {
            gapHorizontal: 15,
            gapVertical: 15,
        }
    }],
    defaultFilter: '*',
    animationType: 'fadeOutTop',
    gapHorizontal: 0,
    gapVertical: 0,
    gridAdjustment: 'responsive',
    caption: 'zoom',

    // lightbox
    lightboxDelegate: '.cbp-lightbox',
    lightboxGallery: true,
    lightboxTitleSrc: 'data-title',

    plugins: {
        loadMore: {
            element: '#js-loadMore-mosaic-flat',
            action: 'click',
            loadItems: 3,
        }
    },
});


/* ===================================
       navbar full 
   ====================================== */
if ($("#sidemenu_toggle").length) {
    $("#sidemenu_toggle").on("click", function () {
        $(".side-menu").removeClass("side-menu-opacity");
        $(".pushwrap").toggleClass("active");
        $(".side-menu").addClass("side-menu-active"), $("#close_side_menu").fadeIn(700)
    }), $("#close_side_menu").on("click", function () {
        $(".side-menu").removeClass("side-menu-active"), $(this).fadeOut(200), $(".pushwrap").removeClass("active");
        setTimeout(function () {
            $(".side-menu").addClass("side-menu-opacity");
        }, 500);
    }), $(".side-nav .navbar-nav .nav-link").on("click", function () {
        $(".side-menu").removeClass("side-menu-active"), $("#close_side_menu").fadeOut(200), $(".pushwrap").removeClass("active");
        setTimeout(function () {
            $(".side-menu").addClass("side-menu-opacity");
        }, 500);
    }), $("#btn_sideNavClose").on("click", function () {
        $(".side-menu").removeClass("side-menu-active"), $("#close_side_menu").fadeOut(200), $(".pushwrap").removeClass("active");
        setTimeout(function () {
            $(".side-menu").addClass("side-menu-opacity");
        }, 500);
    });
}

/* ===================================
  Scroll to Appear
======================================*/

$(window).on('scroll', function () {
    if ($(this).scrollTop() > 500)
        $('.scroll-top-arrow').fadeIn('slow');
    else
        $('.scroll-top-arrow').fadeOut('slow');
});


$(".scroll").on("click", function (event) {
    event.preventDefault();
    $("html,body").animate({
        scrollTop: $(this.hash).offset().top - 88
    });
});

/* ===================================
       Testimonial-Carousel
  ====================================== */
$('.testimonial-carousel').owlCarousel({
    loop: true,
    margin: 30,
    autoplay: true,
    nav: false,
    dots: false,
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 1
        },
        1000: {
            items: 1
        }
    }
})

/* ===================================
    WOW
======================================*/

new WOW().init();



// ====== GALERIA UNEED (isolada) ======
document.addEventListener("DOMContentLoaded", () => {

    const filterButtons = document.querySelectorAll(".ug-filters button");
    const items = document.querySelectorAll(".ug-item");

    // FILTROS
    filterButtons.forEach(btn => {
        btn.addEventListener("click", () => {

            document.querySelector(".ug-filters .active")?.classList.remove("active");
            btn.classList.add("active");

            const filter = btn.dataset.filter;

            items.forEach(item => {
                if (filter === "all" || item.classList.contains(filter)) {
                    item.style.display = "block";
                    setTimeout(() => item.style.opacity = "1", 50);
                } else {
                    item.style.opacity = "0";
                    setTimeout(() => item.style.display = "none", 300);
                }
            });
        });
    });

    // LIGHTBOX
    const lightbox = document.getElementById("ug-lightbox");
    const lightboxImg = document.getElementById("ug-lightbox-img");

    document.querySelectorAll(".ug-item img").forEach(img => {
        img.addEventListener("click", () => {
            lightboxImg.src = img.src;
            lightbox.style.display = "flex";
        });
    });

    document.getElementById("ug-lightbox-close").onclick = () => {
        lightbox.style.display = "none";
    };

    lightbox.onclick = (e) => {
        if (e.target === lightbox) lightbox.style.display = "none";
    };

});

// COOKIES


document.addEventListener("DOMContentLoaded", function () {

  const cookiePopup = document.getElementById('cookie-popup');
  const acceptBtn = document.getElementById('accept-cookies');

  if (cookiePopup && acceptBtn) {

    // 1) Esconder por defeito (evita "flash" e CSS a forçar visível)
    cookiePopup.style.display = 'none';

    // 2) Ler estado (garante consistência)
    const accepted = localStorage.getItem('cookiesAccepted') === 'true';

    // 3) Mostrar apenas se ainda não aceitou
    if (!accepted) {
      cookiePopup.style.display = 'flex';
    }

    // 4) Ao aceitar, guardar string 'true' e esconder
    acceptBtn.addEventListener('click', () => {
      localStorage.setItem('cookiesAccepted', 'true');
      cookiePopup.style.display = 'none';
    });
  }

  /* PRIVACY MODAL (igual ao teu) */
  const privacyModal = document.getElementById('privacy-modal');
  const privacyClose = document.querySelector('.privacy-close');

  if (privacyModal && privacyClose) {
    document.querySelectorAll('#open-privacy, #open-privacy-form').forEach(el => {
      el.addEventListener('click', e => {
        e.preventDefault();
        privacyModal.style.display = 'flex';
      });
    });

    privacyClose.addEventListener('click', () => privacyModal.style.display = 'none');

    privacyModal.addEventListener('click', e => {
      if (e.target === privacyModal) privacyModal.style.display = 'none';
    });
  }

});
