'use client'; import React, { useRef, useState, useCallback, useEffect } from 'react'; import { motion } from 'framer-motion'; import clsx from 'clsx'; import { convertToRgba } from '@/lib/utils'; export const LandingCurvedLinesCtaBg = ({ className, variant = 'default', speed = 'normal', strokeWidth = 2, }: { className?: string; variant?: 'default' | 'primary' | 'secondary'; speed?: 'slow' | 'normal' | 'fast'; strokeWidth?: number; }) => { const domRef = useRef(null); const [animationKey, setAnimationKey] = useState(0); const [colors, setColors] = useState({ color1: '#ccc', color2: '#555' }); const generateNewColors = useCallback(() => { if (!domRef.current) return; const computedStyle = getComputedStyle(domRef.current); let newColors; switch (variant) { case 'primary': { const primaryLighter = computedStyle .getPropertyValue('--primary-lighter') .trim(); const primaryDarker = computedStyle .getPropertyValue('--primary-darker') .trim(); newColors = { color1: convertToRgba({ color: primaryLighter, opacity: 1 }) || '#ccc', color2: convertToRgba({ color: primaryDarker, opacity: 1 }) || '#555', }; break; } case 'secondary': { const secondaryLighter = computedStyle .getPropertyValue('--secondary-lighter') .trim(); const secondaryDarker = computedStyle .getPropertyValue('--secondary-darker') .trim(); newColors = { color1: convertToRgba({ color: secondaryLighter, opacity: 1 }) || '#ccc', color2: convertToRgba({ color: secondaryDarker, opacity: 1 }) || '#555', }; break; } default: { const primaryLighter = computedStyle .getPropertyValue('--primary-lighter') .trim(); const secondaryDarker = computedStyle .getPropertyValue('--secondary-darker') .trim(); newColors = { color1: convertToRgba({ color: primaryLighter, opacity: 1 }) || '#ccc', color2: convertToRgba({ color: secondaryDarker, opacity: 1 }) || '#555', }; break; } } setColors(newColors); }, [variant]); const getAnimationDuration = () => { switch (speed) { case 'slow': return 6; case 'fast': return 2; default: return 4; } }; const duration = getAnimationDuration(); const cycleDuration = (duration + 1) * 1000; // Convert to milliseconds (duration + repeatDelay) const handleCycleReset = useCallback(() => { generateNewColors(); setAnimationKey((prev) => prev + 1); }, [generateNewColors]); // Generate initial colors useEffect(() => { generateNewColors(); }, [generateNewColors]); // Set up timer for cycle resets useEffect(() => { const interval = setInterval(handleCycleReset, cycleDuration); return () => clearInterval(interval); }, [handleCycleReset, cycleDuration]); return (
{/* Top Curves */} {/* Bottom Curves */}
); };