import Masonry from 'masonry-layout';
(function ($) {
	'use strict';
	$(document).ready(function () {
		const selector = '.flo-gallery-grid.flo-gallery-grid--masonry';
		const $galleryArr = $(selector);

		const initMasonry = (container) => {
			// event containers
			if (container.target) {
				container = $(container.target).parents(selector)[0];
			} else {
				// first-call containers
				container = container[0];
			}
			new Masonry(container, {
				itemSelector: '.flo-gallery-grid__image',
				transitionDuration: '0.2s',
				percentPosition: true,
			});
		};

		if ($galleryArr.length) {
			$galleryArr.each(function () {
				const $this = $(this);
				$this.find('img').on('load', initMasonry);
				initMasonry($this);
			});
			$('[data-fancybox]').fancybox({
				loop: true,
				mobile: {
					clickContent: 'close',
					clickSlide: 'close',
					dblclickContent: false,
					dblclickSlide: false,
					dblclickOutside: false,
				},
			});
		}
	});
})(jQuery);
