"use strict";(self.blocksyJsonP=self.blocksyJsonP||[]).push([[87],{87:function(e,t,n){n.r(t),n.d(t,{fetchVideoBy:function(){return s},mount:function(){return y}});var i=n(679),o=n(248);function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const l={},s=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t=c({ignoreVideoOptions:!1},t);let n=ct_localizations.ajax_url+"?action=blocksy_get_image_video_component&media="+e;return t.ignoreVideoOptions&&(n+="&ignore_video_options=true"),new Promise((function(e){(function(e){return l[e]?new Promise((function(t){t(l[e]),l[e]=l[e].clone()})):new Promise((function(t){return fetch(e).then((function(n){t(n),l[e]=n.clone()}))}))})(n).then((function(t){200===t.status&&t.json().then((function(t){let{success:n,data:i}=t;n&&e(i)}))}))}))},u=function(e){e.querySelector(".ct-video-indicator").classList.add("loading"),s(e.dataset.mediaId).then((function(t){const n=document.createElement("div");n.innerHTML=t.html;const o=n.firstChild;e.insertAdjacentElement("beforeend",o);const r=e.querySelector("video,iframe"),a=function(){!function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t=c({onPause:function(){},onPlay:function(){},onReady:function(){}},t),e.isListeningForStateChanges||(e.isListeningForStateChanges=!0,(0,i.pF)(e,(function(n){"pause"===n&&((0,i.Vz)(e),t.onPause()),"play"===n&&(t.onPlay(),(0,i.zT)(e)),"ready"===n&&t.onReady()})))}(r,{onPlay:function(){setTimeout((function(){e.querySelector(".ct-video-indicator").classList.remove("loading")}),120)},onReady:function(){(0,i.Kz)(r)}})};r.matches("video")?r.onloadeddata=a:r.onload=a}))},d=function(e){const t=ct_localizations.dynamic_styles_selectors.find((function(e){return".ct-media-container[data-media-id], .ct-dynamic-media[data-media-id]"===e.selector}));(0,o.Xr)(t.url).then((function(){u(e)}))};ctEvents.on("blocksy:frontend:flexy:slide-change",(function(e){let{instance:t,payload:n}=e;[...t.sliderContainer.querySelectorAll("video,iframe")].map((function(e){return(0,i.r)(e)}));const o=t.sliderContainer.children[n.currentIndex].querySelector(".ct-media-container[data-media-id], .ct-dynamic-media[data-media-id]");if(!o)return;const r=o.querySelector("video,iframe");r?(0,i.v3)(r):f(o,{performVisibilityCheck:!1})}));const f=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t=c({performVisibilityCheck:!0},t),!e.matches('[data-state*="autoplay"]'))return;let n=!0;if(t.performVisibilityCheck&&e.closest(".flexy-items")){const t=e.getBoundingClientRect(),i=e.closest(".flexy-items").getBoundingClientRect();n=t.left>=i.left&&t.left<=i.left+i.width&&t.top>=i.top&&t.top<=i.top+i.height}n&&(e.removeAttribute("data-state"),d(e))};let m=!1;const y=function(e,t){let{event:n}=t;if(!n||"scroll"===n.type){if(m)return;return m=!0,void[...document.querySelectorAll(".ct-media-container[data-media-id]")].map((function(e){f(e)}))}const o=e.querySelector("video,iframe");o?e.matches('[data-state="playing"]')?(0,i.r)(o):(0,i.Kz)(o):d(e)}}}]);