'use client';
import { motion } from 'framer-motion';
import { ReactNode } from 'react';

interface AnimatedCardProps {
  children: ReactNode;
  className?: string;
  delay?: number;
  onClick?: () => void;
  hoverScale?: number;
  hoverY?: number;
}

export default function AnimatedCard({
  children,
  className = '',
  delay = 0,
  onClick,
  hoverScale = 1.015,
  hoverY = -3,
}: AnimatedCardProps) {
  return (
    <motion.div
      initial={{ opacity: 0, y: 16 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true, margin: '-40px' }}
      transition={{ duration: 0.35, delay, ease: [0.25, 0.1, 0.25, 1] }}
      whileHover={{
        scale: hoverScale,
        y: hoverY,
        boxShadow: '0 10px 32px rgba(0,0,0,0.08)',
      }}
      whileTap={{ scale: 0.985 }}
      onClick={onClick}
      className={`bg-white rounded-2xl shadow-sm border border-gray-100 cursor-pointer ${className}`}
      style={{ willChange: 'transform' }}
    >
      {children}
    </motion.div>
  );
}

export function AnimatedStatCard({
  children,
  className = '',
  delay = 0,
  onClick,
}: {
  children: ReactNode;
  className?: string;
  delay?: number;
  onClick?: () => void;
}) {
  return (
    <motion.div
      initial={{ opacity: 0, y: 12, scale: 0.98 }}
      whileInView={{ opacity: 1, y: 0, scale: 1 }}
      viewport={{ once: true, margin: '-30px' }}
      transition={{ duration: 0.4, delay, ease: [0.25, 0.1, 0.25, 1] }}
      whileHover={{
        scale: 1.02,
        y: -4,
        boxShadow: '0 12px 40px rgba(178, 38, 152, 0.08)',
      }}
      whileTap={{ scale: 0.98 }}
      onClick={onClick}
      className={`bg-white rounded-2xl p-5 shadow-sm border border-gray-100 cursor-pointer ${className}`}
      style={{ willChange: 'transform' }}
    >
      {children}
    </motion.div>
  );
}

export function AnimatedTableRow({
  children,
  className = '',
  delay = 0,
}: {
  children: ReactNode;
  className?: string;
  delay?: number;
}) {
  return (
    <motion.tr
      initial={{ opacity: 0, x: -8 }}
      whileInView={{ opacity: 1, x: 0 }}
      viewport={{ once: true }}
      transition={{ duration: 0.25, delay }}
      className={className}
    >
      {children}
    </motion.tr>
  );
}