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