'use client';

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

export default function ProtestWorkflowMockup() {
  const shouldReduceMotion = useReducedMotion();
  const [activeStep, setActiveStep] = useState<number>(1);

  const steps = [
    {
      name: 'Submit',
      status: 'pending',
      color: 'charcoal-outline',
      icon: 'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z'
    },
    {
      name: 'Review',
      status: 'active',
      color: 'warning-amber',
      icon: 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4'
    },
    {
      name: 'Resolve',
      status: 'resolved',
      color: 'performance-green',
      icon: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'
    },
  ];

  const stepVariants = {
    hidden: { opacity: 0, scale: shouldReduceMotion ? 1 : 0.8 },
    visible: (i: number) => ({
      opacity: 1,
      scale: 1,
      transition: {
        delay: shouldReduceMotion ? 0 : i * 0.2,
        type: 'spring' as const,
        stiffness: 200,
        damping: 20
      }
    })
  };

  const arrowVariants = {
    hidden: { opacity: 0, pathLength: 0 },
    visible: (i: number) => ({
      opacity: 1,
      pathLength: 1,
      transition: {
        delay: shouldReduceMotion ? 0 : i * 0.2 + 0.1,
        duration: 0.5,
        ease: 'easeOut' as const
      }
    })
  };

  const getStatusColor = (status: string) => {
    switch (status) {
      case 'pending': return 'bg-charcoal-outline border-charcoal-outline text-gray-500';
      case 'active': return 'bg-warning-amber/20 border-warning-amber text-warning-amber';
      case 'resolved': return 'bg-performance-green/20 border-performance-green text-performance-green';
      default: return 'bg-charcoal-outline border-charcoal-outline text-gray-500';
    }
  };

  return (
    <div className="relative w-full h-full bg-gradient-to-br from-deep-graphite via-iron-gray to-deep-graphite rounded-lg overflow-hidden p-6 flex flex-col justify-center">
      <div className="flex flex-col md:flex-row items-center justify-center gap-4 mb-4">
        {steps.map((step, i) => (
          <div key={step.name} className="flex items-center flex-shrink-0">
                <motion.div
                  custom={i}
                  variants={stepVariants}
                  initial="hidden"
                  animate="visible"
                  className="flex flex-col items-center"
                  onHoverStart={() => !shouldReduceMotion && setActiveStep(i)}
                >
                  <motion.div
                    className={`relative w-12 h-12 md:w-14 md:h-14 rounded-lg flex items-center justify-center mb-2 border-2 ${getStatusColor(step.status)}`}
                  whileHover={shouldReduceMotion ? {} : {
                    scale: 1.1,
                    boxShadow: step.status === 'active'
                      ? '0 0 32px rgba(255,197,86,0.4)'
                      : step.status === 'resolved'
                      ? '0 0 32px rgba(111,227,122,0.4)'
                      : '0 0 20px rgba(34,38,42,0.4)',
                    transition: { duration: 0.2 }
                  }}
                    transition={{ type: 'spring', stiffness: 300, damping: 15 }}
                  >
                    <svg className="w-6 h-6 md:w-7 md:h-7" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                      <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d={step.icon} />
                    </svg>
                    {step.status === 'active' && (
                      <motion.div
                        className="absolute inset-0 rounded-lg"
                        animate={shouldReduceMotion ? {} : {
                          boxShadow: [
                            '0 0 20px rgba(255,197,86,0.3)',
                            '0 0 32px rgba(255,197,86,0.5)',
                            '0 0 20px rgba(255,197,86,0.3)'
                          ]
                        }}
                        transition={{ duration: 2, repeat: Infinity }}
                      />
                    )}
                  </motion.div>
                  <div className="text-xs text-white/70 text-center mb-1">{step.name}</div>
                  <motion.div
                    className={`h-1.5 w-10 md:w-12 rounded ${
                      step.status === 'pending' ? 'bg-charcoal-outline' :
                      step.status === 'active' ? 'bg-warning-amber/30' :
                      'bg-performance-green/30'
                    }`}
                    animate={shouldReduceMotion ? {} : step.status === 'active' ? {
                      opacity: [0.5, 1, 0.5]
                    } : {}}
                    transition={{ duration: 2, repeat: Infinity }}
                  />
                </motion.div>

                {i < steps.length - 1 && (
                  <div className="hidden md:block relative ml-1.5">
                    <svg className="w-5 h-5" viewBox="0 0 24 24" fill="none">
                      <path d="M5 12h14m-7-7l7 7-7 7" stroke="#43C9E6" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
                    </svg>
                  </div>
                )}
          </div>
        ))}
      </div>

      <motion.div
        initial={{ opacity: 0, scaleX: 0 }}
        animate={{ opacity: 1, scaleX: 1 }}
        transition={{ delay: shouldReduceMotion ? 0 : 0.8, duration: 0.6 }}
        className="relative h-1 bg-charcoal-outline rounded-full overflow-hidden"
      >
        <motion.div
          className="absolute inset-y-0 left-0 bg-gradient-to-r from-neon-aqua to-primary-blue rounded-full"
          initial={{ width: '0%' }}
          animate={{ width: `${((activeStep + 1) / steps.length) * 100}%` }}
          transition={{ duration: 0.5, ease: 'easeOut' }}
        />
      </motion.div>
    </div>
  );
}