!function(e){const t={message:null,overlayCSS:{background:"#fff",opacity:.6,cursor:"wait"},fadeIn:10,fadeOut:400,showOverlay:!1},a={message:null,overlayCSS:{background:"#fff",opacity:1,cursor:"wait"},fadeIn:10,fadeOut:100,showOverlay:!1};e.fn.flatsomeVariationImages=function(){return this.each((function(){const i=e(this);if(i.hasClass("ux-variation-images-js-attached"))return;const o=i.closest(".product"),n=jQuery(".product-gallery-slider",o),r=jQuery(".product-thumbnails",o);let l=0,s=!1,d={};const c=e.Deferred(),f=e.Deferred();n.one("flatsome-flickity-ready",(()=>c.resolve())),r.one("flatsome-flickity-ready",(()=>f.resolve())),r.length&&!r.is(":hidden")||f.resolve();const u=e.when(c,f).then((()=>{var e;e=o,s||(d[0]={promise:null,data:{uniqueMainImage:!0,images:e.find(".product-gallery-slider .flickity-slider > *"),thumbs:e.find(".product-thumbnails .flickity-slider > *")}},s=!0),n.on("select.flickity",((e,t)=>{l=t})),i.on("click keydown",".reset_variations",(e=>{if("keydown"===e.type){if("Space"!==e.code&&"Enter"!==e.code)return;e.preventDefault()}m(0)})),i.on("hide_variation",(()=>{m(0)}))}));function m(i=0){if(!o.length)return;let n=o.attr("data-gallery-variation-id");if("undefined"===n&&(n=0,o.attr("data-gallery-variation-id",n)),parseInt(n)===i)return;if(o.attr("data-gallery-variation-id",i),0===i)return g(d[i]),void r.removeClass("ux-additional-variation-images-thumbs-placeholder--visible");const l=function(i,n){const r=e.Deferred((()=>{o.find(".product-gallery-slider").block(t),o.find(".product-thumbnails, .vertical-thumbnails").block(a)}));if(d[i]&&"resolved"===d[i].promise.state())return r.resolve(i,d[i].data);if(!d[i]||"rejected"===d[i].promise.state()){const t=function(t){return e.post(flatsomeVars.ajaxurl,{action:"flatsome_additional_variation_images_load_images_ajax_frontend",variation_id:t})}(i);d[i]={promise:t,data:null}}return e.when(d[i].promise).then((e=>{d[i].data=e.data||null,r.resolve(i,d[i].data)}),(()=>{r.reject()})),r.promise()}(i);l.then((()=>{g(d[i])})),l.always((()=>{o.find(".product-gallery-slider").unblock(),o.find(".product-thumbnails, .vertical-thumbnails").unblock()}))}function g({data:{uniqueMainImage:t,images:a,thumbs:i}}){!t&&a.slice(1).length<1?m(0):(n.find(".flickity-page-dots").fadeToggle(10),n.flickity("remove",n.find(".flickity-slider > *:not(:first)")),e.each(a.slice(1),((t,a)=>{n.flickity("append",e(a))})),r.data("flickity")&&(r.flickity("remove",r.find(".flickity-slider > *:not(:first)")),e.each(i.slice(1),((t,a)=>{r.flickity("append",e(a))})),r.toggleClass("ux-additional-variation-images-thumbs-placeholder--visible",i.slice(1).length>0&&r.hasClass("ux-additional-variation-images-thumbs-placeholder"))),o.imagesLoaded((()=>{l<=a.length-1?n.flickity("select",l):n.flickity("select",0),i.length>4?r.removeClass("slider-no-arrows"):r.addClass("slider-no-arrows"),n.find(".flickity-page-dots").fadeToggle(400),jQuery(document).trigger("flatsome-product-gallery-tools-init"),"undefined"!=typeof PhotoSwipe&&"undefined"!=typeof wc_single_product_params&&e(".woocommerce-product-gallery").off("click").off("click.flatsome").on("click.flatsome",".woocommerce-product-gallery__image a",p)})))}function p(t){t.preventDefault();const a=e(".pswp")[0],i=function(){const t=n.find(".flickity-slider > *");let a=[];return t.length>0&&t.each((function(t,i){var o=e(i).find("img");if(o.length){const e=o.attr("data-large_image"),t=o.attr("data-large_image_width"),i=o.attr("data-large_image_height"),n={alt:o.attr("alt"),src:e,w:t,h:i,title:o.attr("data-caption")?o.attr("data-caption"):o.attr("title")};a.push(n)}})),a}(),o=e(t.target);let r;r=o.is(".woocommerce-product-gallery__trigger")||o.is(".woocommerce-product-gallery__trigger img")?this.$target.find(".flex-active-slide"):o.closest(".woocommerce-product-gallery__image");const l=e.extend({index:e(r).index(),addCaptionHTMLFn:function(e,t){return e.title?(t.children[0].textContent=e.title,!0):(t.children[0].textContent="",!1)}},wc_single_product_params.photoswipe_options);new PhotoSwipe(a,PhotoSwipeUI_Default,i,l).init()}i.on("found_variation",((t,a)=>{"resolved"!==u.state()?e.when(u).done((()=>{m(parseInt(a.variation_id))})):m(parseInt(a.variation_id))})),i.addClass("ux-variation-images-js-attached")}))},e((function(){const t=".variations_form";e(t).flatsomeVariationImages(),e(document).on("wc_variation_form",(function(){e(t).flatsomeVariationImages()})),e(document).ajaxComplete((function(){setTimeout((()=>{e(t).flatsomeVariationImages()}),100)}))}))}(jQuery);