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

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 bikes = [
  {
    id: 1,
    name: 'COPPERHEAD EVO 1',
    price: 'from 3,199.00*',
    image: 'https://www.bulls-bikes.com/media/image/bulls-copperhead-evo-1-product.jpg',
    rating: 5,
    colors: ['#333', '#666', '#999']
  },
  {
    id: 2,
    name: 'EVO CX 1',
    price: '4,799.00*',
    image: 'https://www.bulls-bikes.com/media/image/bulls-evo-cx-1-product.jpg',
    rating: 5,
    colors: ['#333', '#666']
  },
  {
    id: 3,
    name: 'GRINDER 3',
    price: '4,499.00*',
    image: 'https://www.bulls-bikes.com/media/image/bulls-grinder-3-product.jpg',
    rating: 5,
    colors: ['#333', '#666', '#999', '#ccc']
  }
];

const TopEBikes = () => {
  const shouldReduce = useReducedMotion();
  
  const BikeCard = ({ bike, index }) => {
    const content = (
      <div className="bg-white rounded-lg shadow-lg overflow-hidden hover:shadow-xl transition-shadow duration-300">
        <div className="aspect-w-16 aspect-h-12 bg-gray-100">
          <img 
            src={bike.image} 
            alt={bike.name}
            className="w-full h-64 object-cover"
          />
        </div>
        <div className="p-6">
          <div className="flex items-center mb-2">
            {[...Array(bike.rating)].map((_, i) => (
              <Star key={i} className="w-4 h-4 fill-yellow-400 text-yellow-400" />
            ))}
          </div>
          <h3 className="text-xl font-bold text-bulls-dark mb-2">{bike.name}</h3>
          <p className="text-lg font-semibold text-bulls-blue mb-4">{bike.price}</p>
          <div className="flex space-x-2 mb-4">
            {bike.colors.map((color, i) => (
              <div 
                key={i} 
                className="w-6 h-6 rounded-full border-2 border-gray-300"
                style={{ backgroundColor: color }}
              ></div>
            ))}
          </div>
        </div>
      </div>
    );

    if (shouldReduce) {
      return content;
    }

    return (
      <motion.div {...fadeUpPreset(index * 0.1, 0.8)}>
        {content}
      </motion.div>
    );
  };

  const sectionContent = (
    <section className="py-16 bg-white">
      <div className="container mx-auto px-4">
        <div className="text-center mb-12">
          <h2 className="text-4xl font-bold text-bulls-dark mb-4">TOP E-BIKES</h2>
          <div className="flex justify-center space-x-2 mb-8">
            <div className="w-3 h-3 bg-bulls-blue rounded-full"></div>
            <div className="w-3 h-3 bg-gray-300 rounded-full"></div>
            <div className="w-3 h-3 bg-gray-300 rounded-full"></div>
          </div>
        </div>
        
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
          {bikes.map((bike, index) => (
            <BikeCard key={bike.id} bike={bike} index={index} />
          ))}
        </div>
        
        <div className="text-center mt-12">
          <div className="flex justify-center space-x-1">
            {[...Array(8)].map((_, i) => (
              <div 
                key={i} 
                className={`w-2 h-2 rounded-full ${
                  i === 0 ? 'bg-bulls-blue' : 'bg-gray-300'
                }`}
              ></div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );

  if (shouldReduce) {
    return sectionContent;
  }

  return (
    <motion.div {...fadeUpPreset(0.1, 1.0)}>
      {sectionContent}
    </motion.div>
  );
};

export default TopEBikes;