'use client';

import { motion } from 'framer-motion';
import { ReactNode } from 'react';
import Link from 'next/link';

const MotionLink = motion.create(Link);

interface ToolCardProps {
  title: string;
  description: string;
  icon: ReactNode;
  url: string;
  index: number;
  badges?: string[];
}

export default function ToolCard({ title, description, icon, url, index, badges }: ToolCardProps) {
  return (
    <MotionLink
      href={url}
      className="group relative block"
      initial={{ opacity: 0, y: 50 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true }}
      transition={{ duration: 0.5, delay: index * 0.1 }}
      whileHover={{ y: -10 }}
    >
      <div className="glass relative overflow-hidden rounded-2xl p-8 h-full transition-all duration-300 group-hover:shadow-2xl group-hover:bg-card/80">
        {/* Subtle hover overlay */}
        <div className="absolute inset-0 opacity-0 group-hover:opacity-10 transition-opacity duration-300 bg-primary" />

        {/* Icon */}
        <motion.div
          className="mb-6 flex justify-center"
          whileHover={{ scale: 1.1, rotate: 5 }}
          transition={{ type: 'spring', stiffness: 300 }}
        >
          <div className="p-4 rounded-xl bg-primary/10 text-primary shadow-lg shadow-black/5">
            {icon}
          </div>
        </motion.div>

        {/* Title */}
        <h3 className="text-2xl font-bold mb-3 text-foreground transition-all duration-300 group-hover:text-primary">
          {title}
        </h3>

        {/* Badges */}
        {badges && badges.length > 0 && (
          <div className="flex flex-wrap gap-2 mb-3">
            {badges.map((badge) => (
              <span
                key={badge}
                className="text-xs px-2 py-1 rounded-full bg-primary/5 border border-primary/10 text-muted-foreground font-medium"
              >
                {badge}
              </span>
            ))}
          </div>
        )}

        {/* Description */}
        <p className="text-muted-foreground group-hover:text-foreground/80 transition-colors duration-300">
          {description}
        </p>

        {/* Arrow icon */}
        <motion.div
          className="absolute bottom-8 right-8 text-muted-foreground group-hover:text-primary transition-colors duration-300"
          initial={{ x: 0 }}
          whileHover={{ x: 5 }}
        >
          <svg
            className="w-6 h-6"
            fill="none"
            stroke="currentColor"
            viewBox="0 0 24 24"
          >
            <path
              strokeLinecap="round"
              strokeLinejoin="round"
              strokeWidth={2}
              d="M13 7l5 5m0 0l-5 5m5-5H6"
            />
          </svg>
        </motion.div>
      </div>
    </MotionLink>
  );
}
