import { useEffect, useRef } from "react"; import { motion } from "motion/react"; import Button from "@/components/ui/Button"; import HeroBackgroundSlot from "@/components/ui/HeroBackgroundSlot"; import TextAnimation from "@/components/ui/TextAnimation"; import ImageOrVideo from "@/components/ui/ImageOrVideo"; import ScrollReveal from "@/components/ui/ScrollReveal"; import { cls } from "@/lib/utils"; type KpiItem = { value: string; label: string; }; type HeroSplitKpiProps = { tag: string; title: string; description: string; primaryButton: { text: string; href: string }; secondaryButton: { text: string; href: string }; kpis: [KpiItem, KpiItem, KpiItem]; } & ({ imageSrc: string; videoSrc?: never } | { videoSrc: string; imageSrc?: never }); const KPI_POSITIONS = ["top-[5%] left-0", "top-[40%] right-0", "bottom-[5%] left-[5%]"]; const HeroSplitKpi = ({ tag, title, description, primaryButton, secondaryButton, imageSrc, videoSrc, kpis, }: HeroSplitKpiProps) => { const kpiRefs = useRef<(HTMLDivElement | null)[]>([null, null, null]); useEffect(() => { if (window.innerWidth <= 768) return; let mouseX = 0; let mouseY = 0; const offsets = [{ x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }]; const multipliers = [-0.25, -0.5, 0.25]; let animationId: number; const onMouseMove = (e: MouseEvent) => { mouseX = (e.clientX / window.innerWidth) * 100 - 50; mouseY = (e.clientY / window.innerHeight) * 100 - 50; }; const animate = () => { offsets.forEach((offset, i) => { offset.x += ((mouseX * multipliers[i]) - offset.x) * 0.025; offset.y += ((mouseY * multipliers[i]) - offset.y) * 0.025; const el = kpiRefs.current[i]; if (el) el.style.transform = `translate(${offset.x}px, ${offset.y}px)`; }); animationId = requestAnimationFrame(animate); }; animate(); window.addEventListener("mousemove", onMouseMove); return () => { window.removeEventListener("mousemove", onMouseMove); cancelAnimationFrame(animationId); }; }, []); return (

{tag}

{kpis.map((kpi, index) => ( { kpiRefs.current[index] = el; }} initial={{ opacity: 0, scale: 0.9 }} animate={{ opacity: 1, scale: 1 }} transition={{ duration: 0.5, ease: "easeOut", delay: 0.4 + index * 0.1 }} className={cls( "absolute flex flex-col items-center p-3 xl:p-4 2xl:p-5 card backdrop-blur-sm rounded", KPI_POSITIONS[index] )} >

{kpi.value}

{kpi.label}

))}
); }; export default HeroSplitKpi;