import{useState as e,useRef as r,useEffect as t,useCallback as n,useMemo as l}from"react";import{getResponsiveValueByScreen as o,getBgVideoByDevice as a}from"@gem-sdk/core";import s from"./useTranslateValue.js";import i from"./useIntersectionObserver.js";import{getResponsiveSetting as u}from"../common/helpers.js";import m from"../common/animation-manager.js";let p=(p,c,d)=>{let{hoverEffect:g,hoverEffectScale:f,background:x}=p||{},{link:B,enableParallax:b}=c||{},j=Number(c?.speedParallax)||0,[k,v]=e(0),[w,P]=e(null),[$,y]=e(null),[H,N]=e(""),Y=r(null),[h,C]=i(),{translateValue:E}=s({containerBoundingClientRect:w,backgroundBoundingClientRect:$,speed:j}),L=o(c?.layout,d),M=u(x||{}),R=b&&Number(c?.speedParallax||0)>0&&M[d]?.type==="image"||!1;t(()=>{R?N(`translateY(${E}px)`):N("")},[E,R]);let T=n(()=>{if(!R||0===j||!C)return;let e=Number(window.scrollY.toFixed(0));k!==e&&(P(h?.current?h?.current?.getBoundingClientRect():null),y(Y?.current?Y?.current?.getBoundingClientRect():null),v(e))},[k,C,R,j,h,Y]),F=a(x,d),I=l(()=>!!(F?.videoHtml5&&"html5"===F.videoType),[F]);return t(()=>(m.register(T),()=>{m.unregister(T)}),[T]),t(()=>(m.register(T),()=>{m.unregister(T)}),[T]),{onMouseEnterParallax:()=>{g&&R&&N(`${H} scale(${f||"100%"})`)},onMouseLeaveParallax:()=>{g&&R&&N(`translateY(${E}px)`)},bgRef:Y,transform:H,elementRef:h,dataVideo:F,isShowVideoHtml5:I,openLinkBanner:e=>{B?.link&&!e?.srcElement?.closest("a")&&window.open(B?.link,B.target)},layoutResponsive:L}};export{p as default,p as useHeroBanner};
