import React, { useState } from 'react';
import { X, ChefHat, Clock, Target, Lightbulb, Play, ArrowRight, CheckCircle } from 'lucide-react';
import { cn } from '@/utils/cn';

interface ScenarioIntroGuideProps {
  isOpen: boolean;
  onClose: () => void;
  onStart: () => void;
  scenarioType: 'kitchen' | 'general';
  adminLanguage: string;
}

const ScenarioIntroGuide: React.FC<ScenarioIntroGuideProps> = ({
  isOpen,
  onClose,
  onStart,
  scenarioType,
  adminLanguage
}) => {
  const [currentStep, setCurrentStep] = useState(0);

  const steps = [
    {
      title: 'Selamat Datang di Simulasi Skenario!',
      content: 'Anda akan menghadapi situasi nyata di dapur dan harus membuat keputusan yang tepat. Setiap pilihan akan mempengaruhi skor dan kondisi dapur Anda.',
      icon: <ChefHat className="text-blue-600" size={48} />,
      visual: (
        <div className="bg-gradient-to-br from-blue-100 to-indigo-100 p-6 rounded-lg">
          <div className="flex items-center justify-center space-x-4">
            <div className="w-16 h-16 bg-blue-600 rounded-full flex items-center justify-center">
              <ChefHat className="text-white" size={24} />
            </div>
            <ArrowRight className="text-blue-600" size={24} />
            <div className="w-16 h-16 bg-green-600 rounded-full flex items-center justify-center">
              <Target className="text-white" size={24} />
            </div>
          </div>
        </div>
      )
    },
    {
      title: 'Cara Bermain',
      content: 'Baca situasi dengan cermat, pilih tindakan terbaik dari opsi yang tersedia, lalu klik "Jalankan Tindakan" untuk melihat hasilnya.',
      icon: <Play className="text-green-600" size={48} />,
      visual: (
        <div className="space-y-3">
          <div className="p-3 bg-blue-50 border-l-4 border-blue-400 rounded-r">
            <p className="text-sm text-blue-800">
              📖 1. Baca situasi
            </p>
          </div>
          <div className="p-3 bg-yellow-50 border-l-4 border-yellow-400 rounded-r">
            <p className="text-sm text-yellow-800">
              🎯 2. Pilih tindakan
            </p>
          </div>
          <div className="p-3 bg-green-50 border-l-4 border-green-400 rounded-r">
            <p className="text-sm text-green-800">
              ⚡ 3. Jalankan & lihat hasil
            </p>
          </div>
        </div>
      )
    },
    {
      title: 'Memahami Indikator',
      content: 'Perhatikan skor, waktu, kepuasan pelanggan, dan efisiensi. Indikator ini menunjukkan performa Anda dalam mengelola dapur.',
      icon: <Target className="text-purple-600" size={48} />,
      visual: (
        <div className="grid grid-cols-2 gap-3">
          <div className="p-3 bg-red-50 rounded-lg text-center">
            <div className="text-2xl font-bold text-red-600">85</div>
            <div className="text-xs text-red-700">Skor</div>
          </div>
          <div className="p-3 bg-blue-50 rounded-lg text-center">
            <div className="text-2xl font-bold text-blue-600">2:30</div>
            <div className="text-xs text-blue-700">Waktu</div>
          </div>
          <div className="p-3 bg-green-50 rounded-lg text-center">
            <div className="text-2xl font-bold text-green-600">92%</div>
            <div className="text-xs text-green-700">Kepuasan</div>
          </div>
          <div className="p-3 bg-yellow-50 rounded-lg text-center">
            <div className="text-2xl font-bold text-yellow-600">78%</div>
            <div className="text-xs text-yellow-700">Efisiensi</div>
          </div>
        </div>
      )
    },
    {
      title: 'Tips Sukses',
      content: 'Prioritaskan keamanan pangan, kelola waktu dengan baik, dan pertimbangkan dampak jangka panjang dari setiap keputusan Anda.',
      icon: <Lightbulb className="text-yellow-600" size={48} />,
      visual: (
        <div className="space-y-2">
          <div className="flex items-center space-x-2 p-2 bg-green-50 rounded">
            <CheckCircle className="text-green-600" size={16} />
            <span className="text-sm text-green-800">
              Keamanan pangan adalah prioritas utama
            </span>
          </div>
          <div className="flex items-center space-x-2 p-2 bg-blue-50 rounded">
            <CheckCircle className="text-blue-600" size={16} />
            <span className="text-sm text-blue-800">
              Kelola waktu dengan efisien
            </span>
          </div>
          <div className="flex items-center space-x-2 p-2 bg-purple-50 rounded">
            <CheckCircle className="text-purple-600" size={16} />
            <span className="text-sm text-purple-800">
              Pikirkan dampak jangka panjang
            </span>
          </div>
        </div>
      )
    }
  ];

  const handleNext = () => {
    if (currentStep < steps.length - 1) {
      setCurrentStep(currentStep + 1);
    } else {
      onStart();
    }
  };

  const handlePrevious = () => {
    if (currentStep > 0) {
      setCurrentStep(currentStep - 1);
    }
  };

  if (!isOpen) return null;

  const currentStepData = steps[currentStep];

  return (
    <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-xl shadow-2xl max-w-2xl w-full max-h-[90vh] overflow-hidden">
        {/* Header */}
        <div className="flex items-center justify-between p-6 border-b bg-gradient-to-r from-blue-600 to-indigo-600 text-white">
          <div className="flex items-center space-x-3">
            {currentStepData.icon}
            <div>
              <h2 className="text-xl font-bold">{currentStepData.title}</h2>
              <p className="text-blue-100 text-sm">
                Langkah {currentStep + 1} dari {steps.length}
              </p>
            </div>
          </div>
          <button
            onClick={onClose}
            className="p-2 hover:bg-white hover:bg-opacity-20 rounded-full transition-colors"
          >
            <X size={24} />
          </button>
        </div>

        {/* Progress Bar */}
        <div className="px-6 pt-4">
          <div className="w-full bg-gray-200 rounded-full h-2">
            <div 
              className="bg-gradient-to-r from-blue-600 to-indigo-600 h-2 rounded-full transition-all duration-300"
              style={{ width: `${((currentStep + 1) / steps.length) * 100}%` }}
            />
          </div>
        </div>

        {/* Content */}
        <div className="p-6 space-y-6">
          {/* Visual */}
          <div className="flex justify-center">
            {currentStepData.visual}
          </div>

          {/* Description */}
          <div className="text-center">
            <p className="text-gray-700 text-lg leading-relaxed">
              {currentStepData.content}
            </p>
          </div>

          {/* Additional Info for Kitchen Scenarios */}
          {scenarioType === 'kitchen' && currentStep === 0 && (
            <div className="bg-orange-50 border border-orange-200 rounded-lg p-4">
              <div className="flex items-start space-x-3">
                <ChefHat className="text-orange-600 mt-1" size={20} />
                <div>
                  <h4 className="font-semibold text-orange-900 mb-1">
                    Simulasi Dapur MBG
                  </h4>
                  <p className="text-orange-800 text-sm">
                    Simulasi ini dibuat khusus untuk melatih kemampuan Anda mengelola dapur dengan standar kebersihan dan keamanan makanan yang baik sesuai aturan MBG.
                  </p>
                </div>
              </div>
            </div>
          )}
        </div>

        {/* Footer */}
        <div className="flex items-center justify-between p-6 border-t bg-gray-50">
          <button
            onClick={handlePrevious}
            disabled={currentStep === 0}
            className={cn(
              'px-4 py-2 rounded-lg font-medium transition-colors',
              currentStep === 0
                ? 'bg-gray-200 text-gray-400 cursor-not-allowed'
                : 'bg-gray-300 text-gray-700 hover:bg-gray-400'
            )}
          >
              Sebelumnya
            </button>

          <div className="flex space-x-2">
            {steps.map((_, index) => (
              <div
                key={index}
                className={cn(
                  'w-3 h-3 rounded-full transition-colors',
                  index === currentStep ? 'bg-blue-600' : 'bg-gray-300'
                )}
              />
            ))}
          </div>

          <button
              onClick={handleNext}
              className="px-6 py-2 bg-gradient-to-r from-blue-600 to-indigo-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-indigo-700 transition-colors"
            >
              {currentStep === steps.length - 1 
                ? 'Mulai Bermain'
                : 'Lanjut'
              }
            </button>
        </div>
      </div>
    </div>
  );
};

export default ScenarioIntroGuide;