// Add Fancybox
import { Fancybox } from 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.esm.js';

// Add Carousel
// import '@fancyapps/ui/dist/carousel.css';
import { Carousel } from 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/carousel.esm.js';

// Add `Autoplay` plugin
import { Autoplay } from 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/carousel.autoplay.esm.js';
Carousel.Plugins.Autoplay = Autoplay;

//fancybox
if(Fancybox){
    Fancybox.bind('[data-fancybox="media-img"]', {
        dragToClose: false,
    
        Toolbar: false,
        closeButton: "top",
      
        Image: {
          zoom: false,
        },
      
        on: {
          initCarousel: (fancybox) => {
            const slide = fancybox.Carousel.slides[fancybox.Carousel.page];
      
            fancybox.$container.style.setProperty(
              "--bg-image",
              `url("${slide.$thumb.src}")`
            );
          },
          "Carousel.change": (fancybox, carousel, to, from) => {
            const slide = carousel.slides[to];
      
            fancybox.$container.style.setProperty(
              "--bg-image",
              `url("${slide.$thumb.src}")`
            );
          },
        },
      });

}
