"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@gem-sdk/core"),r=require("../common/helpers.js");exports.default=({videoType:i,sizeSetting:o,background:u,videoObjectFit:n,heroBannerWrapperRef:s,isYoutubeVideoMigrated:a})=>{let l=t.useCurrentDevice(),f=e.useRef(null),m=e.useMemo(()=>r.getAspectRatio(o,u),[o,u]),c=e.useMemo(()=>r.getYoutubeAspectRatio(u,n,m),[u,n,m]),d=r.getResponsiveSetting(n||{}),y=t.getResponsiveValueByScreen(d,l),v=t.getResponsiveValueByScreen(u,l),p=v?.loop;return e.useEffect(()=>{if("youtube"!==i)return;let e=f.current;if(!e)return;let o=e?.querySelector("iframe");if(!o)return;let n=t.getResponsiveValueByScreen(u,l),s=n?.videoAlign;r.setVideoIframeAlign(o,s)},[u,l,i]),e.useEffect(()=>{let e=f.current,t=s?.current,o=()=>e?.querySelector("iframe"),n=i=>{let n=i||e;if(!n)return;let s=n.querySelector("iframe");r.updateVideoIframeSize({iframeEl:s||o(),containerRatio:r.getContainerRatio(t),videoObjectFit:y||"cover",background:u,currentDevice:l,isYoutubeVideoMigrated:a})},m=e=>{let t=e.detail?.iframe;if(t){let e=t.closest("article"),r=e?.parentElement;setTimeout(()=>{n(r)},50)}};if(t&&t.addEventListener("youtube-iframe-ready",m),!e)return()=>{t&&t.removeEventListener("youtube-iframe-ready",m)};if("youtube"!==i){let i=o();return i&&r.resetVideoIframeStyle(i),r.resetVideoWrapperStyle(e),()=>{t&&t.removeEventListener("youtube-iframe-ready",m)}}r.setVideoWrapperStyle(e),o()&&(window.requestAnimationFrame(()=>n()),setTimeout(()=>{n()},100));let c=window.ResizeObserver;if(!c)return()=>{t&&t.removeEventListener("youtube-iframe-ready",m)};let d=new c(()=>n());return t&&d.observe(t),()=>{if(d.disconnect(),t&&t.removeEventListener("youtube-iframe-ready",m),e){let t=o();t&&r.resetVideoIframeStyle(t),r.resetVideoWrapperStyle(e)}}},[i,y,l,m,p]),{youtubeIframeWrapperRef:f,resolvedAspectRatio:m,youtubeAspectRatio:c}};
