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