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" }
});

function LivePreview() {
  const shouldReduce = useReducedMotion();
  
  if (shouldReduce) {
    return (
      <section className="section-padding bg-nest-dark text-white">
        <div className="container-custom text-center">
          <h2 className="text-4xl md:text-5xl font-bold mb-6">
            Live preview
          </h2>
          <p className="text-xl text-gray-300 mb-12 max-w-2xl mx-auto">
            See NestJS in action with our interactive examples and live coding environment.
          </p>
          <div className="bg-black/50 rounded-lg p-8 max-w-4xl mx-auto">
            <div className="text-left">
              <div className="flex items-center gap-2 mb-4">
                <div className="w-3 h-3 bg-red-500 rounded-full"></div>
                <div className="w-3 h-3 bg-yellow-500 rounded-full"></div>
                <div className="w-3 h-3 bg-green-500 rounded-full"></div>
              </div>
              <div className="font-mono text-sm text-gray-300">
                <div className="text-blue-400">import</div>
                <div className="ml-4">{'{ Controller, Get }'} <span className="text-blue-400">from</span> <span className="text-green-400">'@nestjs/common'</span>;</div>
                <div className="mt-4 text-yellow-400">@Controller()</div>
                <div className="text-blue-400">export class</div>
                <div className="ml-4">AppController {'{'}</div>
                <div className="ml-8 text-yellow-400">@Get()</div>
                <div className="ml-8">getHello(): <span className="text-blue-400">string</span> {'{'}</div>
                <div className="ml-12 text-blue-400">return</div>
                <div className="ml-16 text-green-400">'Hello World!'</div>
                <div className="ml-8">{'}'}</div>
                <div className="ml-4">{'}'}</div>
              </div>
            </div>
          </div>
        </div>
      </section>
    );
  }

  return (
    <motion.section 
      {...fadeUpPreset(0.1, 1.0)}
      className="section-padding bg-nest-dark text-white"
    >
      <div className="container-custom text-center">
        <motion.h2 
          {...fadeUpPreset(0.2, 0.8)}
          className="text-4xl md:text-5xl font-bold mb-6"
        >
          Live preview
        </motion.h2>
        <motion.p 
          {...fadeUpPreset(0.3, 0.8)}
          className="text-xl text-gray-300 mb-12 max-w-2xl mx-auto"
        >
          See NestJS in action with our interactive examples and live coding environment.
        </motion.p>
        <motion.div 
          {...fadeUpPreset(0.4, 0.8)}
          className="bg-black/50 rounded-lg p-8 max-w-4xl mx-auto"
        >
          <div className="text-left">
            <div className="flex items-center gap-2 mb-4">
              <div className="w-3 h-3 bg-red-500 rounded-full"></div>
              <div className="w-3 h-3 bg-yellow-500 rounded-full"></div>
              <div className="w-3 h-3 bg-green-500 rounded-full"></div>
            </div>
            <div className="font-mono text-sm text-gray-300">
              <div className="text-blue-400">import</div>
              <div className="ml-4">{'{ Controller, Get }'} <span className="text-blue-400">from</span> <span className="text-green-400">'@nestjs/common'</span>;</div>
              <div className="mt-4 text-yellow-400">@Controller()</div>
              <div className="text-blue-400">export class</div>
              <div className="ml-4">AppController {'{'}</div>
              <div className="ml-8 text-yellow-400">@Get()</div>
              <div className="ml-8">getHello(): <span className="text-blue-400">string</span> {'{'}</div>
              <div className="ml-12 text-blue-400">return</div>
              <div className="ml-16 text-green-400">'Hello World!'</div>
              <div className="ml-8">{'}'}</div>
              <div className="ml-4">{'}'}</div>
            </div>
          </div>
        </motion.div>
      </div>
    </motion.section>
  );
}

export default LivePreview;