"use client"; import { memo, useEffect, useId, useRef, useState } from "react"; import { motion } from "framer-motion"; import { cls } from "@/lib/utils"; interface AnimatedGridBackgroundProps { className?: string; squareSize?: number; numSquares?: number; maxOpacity?: number; perspectiveThreeD?: boolean; } const AnimatedGridBackground = ({ className = "", squareSize = 100, numSquares = 50, maxOpacity = 0.15, perspectiveThreeD = true, }: AnimatedGridBackgroundProps) => { const id = useId(); const containerRef = useRef(null); const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); const [squares, setSquares] = useState>([]); useEffect(() => { if (containerRef.current) { const { width, height } = containerRef.current.getBoundingClientRect(); setDimensions({ width, height }); } }, []); useEffect(() => { if (dimensions.width && dimensions.height) { const cols = Math.ceil(dimensions.width / squareSize); const rows = Math.ceil(dimensions.height / squareSize); const newSquares = Array.from({ length: numSquares }, (_, i) => ({ id: i, pos: [ Math.floor(Math.random() * cols), Math.floor(Math.random() * rows), ] as [number, number], })); setSquares(newSquares); } }, [dimensions, squareSize, numSquares]); return ( ); }; AnimatedGridBackground.displayName = "AnimatedGridBackground"; export default memo(AnimatedGridBackground);