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