import React from 'react';
import { motion, useReducedMotion } from 'framer-motion';

const fadeUpPreset = (delay = 0, duration = 1.2) => ({
  initial: { opacity: 0, y: 20 },
  whileInView: { opacity: 1, y: 0 },
  viewport: { once: true, amount: 0.2 },
  transition: { delay, duration, ease: "easeOut" }
});

const Features = () => {
  const shouldReduce = useReducedMotion();

  const features = [
    {
      icon: (
        <svg className="feature-icon" viewBox="0 0 64 64" fill="none">
          <path d="M32 8L8 20v24l24 12 24-12V20L32 8z" stroke="#e0234e" strokeWidth="2" fill="none"/>
          <path d="M32 32L8 20" stroke="#e0234e" strokeWidth="2"/>
          <path d="M32 32L56 20" stroke="#e0234e" strokeWidth="2"/>
          <path d="M32 32v20" stroke="#e0234e" strokeWidth="2"/>
        </svg>
      ),
      title: "EXTENSIBLE",
      description: "Provides unparalleled flexibility through its meticulously crafted modular architecture."
    },
    {
      icon: (
        <svg className="feature-icon" viewBox="0 0 64 64" fill="none">
          <path d="M32 8l8 8-8 8-8-8 8-8z" stroke="#e0234e" strokeWidth="2" fill="none"/>
          <path d="M16 24l8 8-8 8-8-8 8-8z" stroke="#e0234e" strokeWidth="2" fill="none"/>
          <path d="M48 24l8 8-8 8-8-8 8-8z" stroke="#e0234e" strokeWidth="2" fill="none"/>
          <path d="M32 40l8 8-8 8-8-8 8-8z" stroke="#e0234e" strokeWidth="2" fill="none"/>
          <circle cx="32" cy="16" r="2" fill="#e0234e"/>
          <circle cx="16" cy="32" r="2" fill="#e0234e"/>
          <circle cx="48" cy="32" r="2" fill="#e0234e"/>
          <circle cx="32" cy="48" r="2" fill="#e0234e"/>
        </svg>
      ),
      title: "VERSATILE",
      description: "Serves as a robust, elegant, and well-structured foundation for all kinds of server-side applications."
    },
    {
      icon: (
        <svg className="feature-icon" viewBox="0 0 64 64" fill="none">
          <path d="M32 8L16 24v24l16 8 16-8V24L32 8z" stroke="#e0234e" strokeWidth="2" fill="none"/>
          <path d="M32 24L16 32" stroke="#e0234e" strokeWidth="2"/>
          <path d="M32 24L48 32" stroke="#e0234e" strokeWidth="2"/>
          <path d="M32 24v24" stroke="#e0234e" strokeWidth="2"/>
          <circle cx="32" cy="16" r="3" fill="#e0234e"/>
          <circle cx="24" cy="28" r="2" fill="#e0234e"/>
          <circle cx="40" cy="28" r="2" fill="#e0234e"/>
        </svg>
      ),
      title: "PROGRESSIVE",
      description: "Introduces design patterns and well-established solutions to the Node.js landscape."
    }
  ];

  if (shouldReduce) {
    return (
      <section className="py-20 bg-nest-light-gray">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
          <div className="grid grid-cols-1 md:grid-cols-3 gap-12">
            {features.map((feature, index) => (
              <div key={index} className="feature-card">
                {feature.icon}
                <h3 className="text-xl font-bold text-nest-red mb-4">
                  {feature.title}
                </h3>
                <p className="text-nest-gray leading-relaxed">
                  {feature.description}
                </p>
              </div>
            ))}
          </div>
        </div>
      </section>
    );
  }

  return (
    <motion.section 
      {...fadeUpPreset(0.1, 1.0)}
      className="py-20 bg-nest-light-gray"
    >
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div className="grid grid-cols-1 md:grid-cols-3 gap-12">
          {features.map((feature, index) => (
            <motion.div 
              key={index} 
              {...fadeUpPreset(index * 0.1, 0.8)}
              className="feature-card"
            >
              {feature.icon}
              <h3 className="text-xl font-bold text-nest-red mb-4">
                {feature.title}
              </h3>
              <p className="text-nest-gray leading-relaxed">
                {feature.description}
              </p>
            </motion.div>
          ))}
        </div>
      </div>
    </motion.section>
  );
};

export default Features;