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 LivePreview = () => {
  const shouldReduce = useReducedMotion();

  if (shouldReduce) {
    return (
      <section className="section-padding bg-nest-dark text-white">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
          <h2 className="text-4xl lg:text-5xl font-bold mb-6">
            Live preview
          </h2>
          <p className="text-gray-300 text-lg mb-12 max-w-3xl mx-auto">
            See NestJS in action with our interactive examples and live coding environment.
          </p>
          
          <div className="bg-gray-900 rounded-lg p-8 max-w-4xl mx-auto">
            <div className="bg-gray-800 rounded p-6 text-left">
              <div className="flex items-center mb-4">
                <div className="flex space-x-2">
                  <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>
                <span className="ml-4 text-gray-400 text-sm">app.controller.ts</span>
              </div>
              <pre className="text-green-400 text-sm overflow-x-auto">
{`import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }
}`}
              </pre>
            </div>
          </div>
        </div>
      </section>
    );
  }

  return (
    <motion.section 
      {...fadeUpPreset(0.1, 1.0)}
      className="section-padding bg-nest-dark text-white"
    >
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
        <motion.h2 
          {...fadeUpPreset(0.2, 0.8)}
          className="text-4xl lg:text-5xl font-bold mb-6"
        >
          Live preview
        </motion.h2>
        <motion.p 
          {...fadeUpPreset(0.3, 0.8)}
          className="text-gray-300 text-lg mb-12 max-w-3xl 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-gray-900 rounded-lg p-8 max-w-4xl mx-auto"
        >
          <div className="bg-gray-800 rounded p-6 text-left">
            <div className="flex items-center mb-4">
              <div className="flex space-x-2">
                <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>
              <span className="ml-4 text-gray-400 text-sm">app.controller.ts</span>
            </div>
            <pre className="text-green-400 text-sm overflow-x-auto">
{`import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }
}`}
            </pre>
          </div>
        </motion.div>
      </div>
    </motion.section>
  );
};

export default LivePreview;