'use client'; import { useState, useRef, useEffect } from 'react'; import styles from './heal-pulse.module.css'; export interface HealPulseProps { children: React.ReactNode; /** Type of healing effect */ color?: 'nature' | 'holy' | 'mystic' | 'water' | 'life'; /** Number of healing waves */ waves?: number; /** Speed of the waves */ speed?: 'slow' | 'medium' | 'fast'; /** Size of the effect */ size?: 'small' | 'medium' | 'large' | 'xlarge'; /** Trigger animation on click */ triggerOnClick?: boolean; /** Auto-trigger on mount */ autoTrigger?: boolean; /** Show floating particles */ particles?: boolean; /** Show cross pattern (holy) */ showCross?: boolean; } export function HealPulse({ children, color = 'nature', waves = 5, speed = 'medium', size = 'medium', triggerOnClick = true, autoTrigger = false, particles = true, showCross = false, }: HealPulseProps) { const [isActive, setIsActive] = useState(false); const timeoutRef = useRef(); const trigger = () => { setIsActive(false); // Force reflow requestAnimationFrame(() => { requestAnimationFrame(() => { setIsActive(true); timeoutRef.current = setTimeout(() => { setIsActive(false); }, 3000); }); }); }; useEffect(() => { if (autoTrigger) { trigger(); } return () => { if (timeoutRef.current) clearTimeout(timeoutRef.current); }; }, []); // Generate sparkle particles const sparkles = Array.from({ length: 12 }, (_, i) => { const angle = (i / 12) * Math.PI * 2; const distance = 50 + Math.random() * 100; return { tx: Math.cos(angle) * distance, ty: Math.sin(angle) * distance - 50, delay: Math.random() * 0.5, }; }); // Generate leaves for nature type const leaves = Array.from({ length: 8 }, (_, i) => ({ tx: (Math.random() - 0.5) * 100, ty: 50 + Math.random() * 50, delay: Math.random() * 0.3, })); // Generate plus symbols for holy type const plusSymbols = Array.from({ length: 6 }, (_, i) => ({ tx: (Math.random() - 0.5) * 80, ty: -60 - Math.random() * 60, delay: Math.random() * 0.4, })); return (
{isActive && (
{/* Central glow */}
{/* Healing waves */} {Array.from({ length: waves }).map((_, i) => (
))} {/* Sparkles (all types) */} {particles && sparkles.map((sparkle, i) => (
))} {/* Leaves (nature type) */} {color === 'nature' && particles && leaves.map((leaf, i) => (
))} {/* Plus symbols (holy type) */} {color === 'holy' && particles && plusSymbols.map((plus, i) => (
+
))}
)} {children}
); } export default HealPulse;