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}=c||{},b=Number(c?.speedParallax)||0,[j,w]=e(0),[H,$]=e(null),[k,v]=e(null),[y,N]=e(""),Y=r(null),[h,C]=i(),{translateValue:P}=a({containerBoundingClientRect:H,backgroundBoundingClientRect:k,speed:b}),R=o(c?.layout,d),T=m(x||{}),E=Number(c?.speedParallax||0)>0&&T[d]?.type==="image",F=()=>{g&&E&&N(`${y} scale(${f||"100%"})`)},I=()=>{g&&E&&N(`translateY(${P}px)`)},O=e=>{B?.link&&!e?.srcElement?.closest("a")&&window.open(B?.link,B.target)};t(()=>{E?N(`translateY(${P}px)`):N("")},[P,E]);let V=n(()=>{if(!E||0===b||!C)return;let e=Number(window.scrollY.toFixed(0));j!==e&&($(h?.current?h?.current?.getBoundingClientRect():null),v(Y?.current?Y?.current?.getBoundingClientRect():null),w(e))},[j,C,E,b,h,Y]),q=s(x,d),z=l(()=>!!(q?.videoHtml5&&"html5"===q.videoType),[q]);return t(()=>(u.register(V),()=>{u.unregister(V)}),[V]),t(()=>(u.register(V),()=>{u.unregister(V)}),[V]),{onMouseEnterParallax:F,onMouseLeaveParallax:I,bgRef:Y,transform:y,elementRef:h,dataVideo:q,isShowVideoHtml5:z,openLinkBanner:O,layoutResponsive:R}};export{useHeroBanner as default,useHeroBanner};
