"use client"

import { useState, useEffect } from "react"
import { Button } from "@/components/ui/button"
import { AnimatedButton } from "@/components/ui/animated-button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { AnimatedCard } from "@/components/ui/animated-card"
import { Badge } from "@/components/ui/badge"
import { Header } from "@/components/ui/header"
import { Footer } from "@/components/ui/footer"
import {
  CheckCircle,
  Calendar,
  Clock,
  MapPin,
  Phone,
  Mail,
  Users,
  ArrowRight,
  Download,
  Share2,
  Edit3,
  Home
} from "lucide-react"
import Image from "next/image"
import Link from "next/link"
import { motion } from "framer-motion"

// Mock tour data - in real app this would come from URL params or API
const mockTourData = {
  confirmationNumber: "TGG-2024-001547",
  facility: {
    name: "Sunrise Senior Living",
    type: "Assisted Living",
    address: "123 Oak Street, Springfield, IL 62701",
    phone: "(555) 123-4567",
    email: "tours@sunriseseniorliving.com",
    image: "/senior-living-facility-exterior.jpg"
  },
  tourDetails: {
    date: "2024-02-15",
    time: "2:00 PM",
    duration: "60 minutes",
    visitors: 2,
    tourGuide: "Sarah Johnson",
    specialRequests: "Interested in memory care options"
  },
  contactPerson: {
    name: "John Smith",
    email: "john.smith@example.com",
    phone: "(555) 987-6543"
  }
}

export default function TourConfirmationPage() {
  const [isLoading, setIsLoading] = useState(true)
  const [showSuccess, setShowSuccess] = useState(false)

  useEffect(() => {
    // Simulate loading
    const timer = setTimeout(() => {
      setIsLoading(false)
      setShowSuccess(true)
    }, 1000)
    return () => clearTimeout(timer)
  }, [])

  const handleDownloadConfirmation = () => {
    // In real app, this would generate and download a PDF
    console.log("Downloading confirmation...")
  }

  const handleShareConfirmation = () => {
    // In real app, this would open share dialog
    console.log("Sharing confirmation...")
  }

  const handleReschedule = () => {
    // In real app, this would open reschedule modal
    console.log("Rescheduling tour...")
  }

  if (isLoading) {
    return (
      <div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-blue-50/30 flex items-center justify-center">
        <div className="text-center">
          <div className="w-16 h-16 border-4 border-[#3F5CEA] border-t-transparent rounded-full animate-spin mx-auto mb-4"></div>
          <h3 className="font-primary text-2xl font-bold text-slate-800 mb-2">Confirming Your Tour</h3>
          <p className="font-body text-lg text-slate-600">Processing your tour request...</p>
        </div>
      </div>
    )
  }

  return (
    <div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-blue-50/30">
      <Header />

      <div className="container mx-auto px-4 py-12">
        <div className="max-w-4xl mx-auto">
          {/* Success Animation */}
          <motion.div
            initial={{ opacity: 0, scale: 0.8 }}
            animate={{ opacity: 1, scale: 1 }}
            transition={{ duration: 0.6, type: "spring", stiffness: 300 }}
            className="text-center mb-8"
          >
            <div className="mx-auto mb-6 w-24 h-24 rounded-full bg-gradient-to-br from-green-500 to-green-600 flex items-center justify-center shadow-lg">
              <CheckCircle className="h-12 w-12 text-white" />
            </div>

            <h1 className="font-primary text-4xl md:text-5xl font-bold text-gray-900 mb-4">
              Tour Scheduled Successfully!
            </h1>

            <p className="font-body text-xl text-gray-600 max-w-2xl mx-auto leading-relaxed">
              Your facility tour has been confirmed. We've sent you a confirmation email with all the details.
            </p>

            <Badge className="mt-4 bg-green-100 text-green-800 text-lg px-4 py-2">
              Confirmation #{mockTourData.confirmationNumber}
            </Badge>
          </motion.div>

          <div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
            {/* Tour Details */}
            <div className="lg:col-span-2 space-y-6">
              {/* Facility Information */}
              <AnimatedCard className="overflow-hidden">
                <CardHeader className="bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-blue-200/50">
                  <CardTitle className="font-primary text-2xl text-gray-900 flex items-center gap-3">
                    <MapPin className="h-6 w-6 text-[#3F5CEA]" />
                    Facility Information
                  </CardTitle>
                </CardHeader>
                <CardContent className="p-6">
                  <div className="flex flex-col md:flex-row gap-6">
                    <div className="md:w-48 h-32 relative rounded-lg overflow-hidden">
                      <Image
                        src={mockTourData.facility.image}
                        alt={mockTourData.facility.name}
                        fill
                        className="object-cover"
                      />
                    </div>
                    <div className="flex-1">
                      <h3 className="font-primary text-2xl font-bold text-gray-900 mb-2">
                        {mockTourData.facility.name}
                      </h3>
                      <Badge variant="secondary" className="mb-3 bg-blue-100 text-blue-800">
                        {mockTourData.facility.type}
                      </Badge>
                      <div className="space-y-2">
                        <div className="flex items-center gap-2 text-gray-600">
                          <MapPin className="h-4 w-4" />
                          <span className="font-body">{mockTourData.facility.address}</span>
                        </div>
                        <div className="flex items-center gap-2 text-gray-600">
                          <Phone className="h-4 w-4" />
                          <span className="font-body">{mockTourData.facility.phone}</span>
                        </div>
                        <div className="flex items-center gap-2 text-gray-600">
                          <Mail className="h-4 w-4" />
                          <span className="font-body">{mockTourData.facility.email}</span>
                        </div>
                      </div>
                    </div>
                  </div>
                </CardContent>
              </AnimatedCard>

              {/* Tour Details */}
              <AnimatedCard>
                <CardHeader className="bg-gradient-to-r from-green-50 to-blue-50 border-b border-green-200/50">
                  <CardTitle className="font-primary text-2xl text-gray-900 flex items-center gap-3">
                    <Calendar className="h-6 w-6 text-[#3F5CEA]" />
                    Tour Details
                  </CardTitle>
                </CardHeader>
                <CardContent className="p-6">
                  <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div className="space-y-4">
                      <div className="bg-gradient-to-r from-blue-50 to-indigo-50 p-4 rounded-lg border border-blue-200/50">
                        <div className="flex items-center gap-3 mb-2">
                          <Calendar className="h-5 w-5 text-[#3F5CEA]" />
                          <span className="font-body font-medium text-gray-900">Date</span>
                        </div>
                        <p className="font-primary text-xl font-bold text-gray-900">
                          {new Date(mockTourData.tourDetails.date).toLocaleDateString('en-US', {
                            weekday: 'long',
                            year: 'numeric',
                            month: 'long',
                            day: 'numeric'
                          })}
                        </p>
                      </div>

                      <div className="bg-gradient-to-r from-green-50 to-blue-50 p-4 rounded-lg border border-green-200/50">
                        <div className="flex items-center gap-3 mb-2">
                          <Clock className="h-5 w-5 text-[#3F5CEA]" />
                          <span className="font-body font-medium text-gray-900">Time</span>
                        </div>
                        <p className="font-primary text-xl font-bold text-gray-900">
                          {mockTourData.tourDetails.time}
                        </p>
                        <p className="font-body text-gray-600">
                          Duration: {mockTourData.tourDetails.duration}
                        </p>
                      </div>
                    </div>

                    <div className="space-y-4">
                      <div className="bg-gradient-to-r from-purple-50 to-pink-50 p-4 rounded-lg border border-purple-200/50">
                        <div className="flex items-center gap-3 mb-2">
                          <Users className="h-5 w-5 text-[#3F5CEA]" />
                          <span className="font-body font-medium text-gray-900">Visitors</span>
                        </div>
                        <p className="font-primary text-xl font-bold text-gray-900">
                          {mockTourData.tourDetails.visitors} {mockTourData.tourDetails.visitors === 1 ? 'person' : 'people'}
                        </p>
                      </div>

                      <div className="bg-gradient-to-r from-orange-50 to-red-50 p-4 rounded-lg border border-orange-200/50">
                        <div className="flex items-center gap-3 mb-2">
                          <Users className="h-5 w-5 text-[#3F5CEA]" />
                          <span className="font-body font-medium text-gray-900">Tour Guide</span>
                        </div>
                        <p className="font-primary text-xl font-bold text-gray-900">
                          {mockTourData.tourDetails.tourGuide}
                        </p>
                      </div>
                    </div>
                  </div>

                  {mockTourData.tourDetails.specialRequests && (
                    <div className="mt-6 bg-gradient-to-r from-yellow-50 to-orange-50 p-4 rounded-lg border border-yellow-200/50">
                      <h4 className="font-body font-medium text-gray-900 mb-2">Special Requests</h4>
                      <p className="font-body text-gray-700">{mockTourData.tourDetails.specialRequests}</p>
                    </div>
                  )}
                </CardContent>
              </AnimatedCard>
            </div>

            {/* Actions Sidebar */}
            <div className="space-y-6">
              {/* Quick Actions */}
              <AnimatedCard>
                <CardHeader>
                  <CardTitle className="font-primary text-xl text-gray-900">Quick Actions</CardTitle>
                </CardHeader>
                <CardContent className="space-y-3">
                  <AnimatedButton
                    onClick={handleDownloadConfirmation}
                    className="w-full bg-gradient-to-r from-[#3F5CEA] to-[#5B73F0] hover:from-[#09183D] hover:to-[#3F5CEA] text-white"
                  >
                    <Download className="h-4 w-4 mr-2" />
                    Download Confirmation
                  </AnimatedButton>

                  <Button
                    variant="outline"
                    onClick={handleShareConfirmation}
                    className="w-full border-[#3F5CEA] text-[#3F5CEA] hover:bg-[#3F5CEA] hover:text-white"
                  >
                    <Share2 className="h-4 w-4 mr-2" />
                    Share Details
                  </Button>

                  <Button
                    variant="outline"
                    onClick={handleReschedule}
                    className="w-full border-gray-300 text-gray-700 hover:bg-gray-50"
                  >
                    <Edit3 className="h-4 w-4 mr-2" />
                    Reschedule Tour
                  </Button>
                </CardContent>
              </AnimatedCard>

              {/* Contact Information */}
              <AnimatedCard>
                <CardHeader>
                  <CardTitle className="font-primary text-xl text-gray-900">Your Contact Info</CardTitle>
                </CardHeader>
                <CardContent>
                  <div className="space-y-3">
                    <div>
                      <p className="font-body font-medium text-gray-900">{mockTourData.contactPerson.name}</p>
                      <p className="font-body text-gray-600">{mockTourData.contactPerson.email}</p>
                      <p className="font-body text-gray-600">{mockTourData.contactPerson.phone}</p>
                    </div>
                    <div className="pt-3 border-t border-gray-200">
                      <p className="font-body text-sm text-gray-500">
                        We'll use this information to send you tour reminders and updates.
                      </p>
                    </div>
                  </div>
                </CardContent>
              </AnimatedCard>

              {/* What's Next */}
              <AnimatedCard className="bg-gradient-to-br from-blue-50 to-indigo-50 border-blue-200">
                <CardHeader>
                  <CardTitle className="font-primary text-xl text-blue-900">What's Next?</CardTitle>
                </CardHeader>
                <CardContent>
                  <div className="space-y-4">
                    <div className="flex items-start gap-3">
                      <div className="w-6 h-6 rounded-full bg-blue-600 text-white flex items-center justify-center text-sm font-bold">1</div>
                      <div>
                        <p className="font-body font-medium text-blue-900">Check Your Email</p>
                        <p className="font-body text-sm text-blue-700">Confirmation details sent to your inbox</p>
                      </div>
                    </div>
                    <div className="flex items-start gap-3">
                      <div className="w-6 h-6 rounded-full bg-blue-600 text-white flex items-center justify-center text-sm font-bold">2</div>
                      <div>
                        <p className="font-body font-medium text-blue-900">Prepare Questions</p>
                        <p className="font-body text-sm text-blue-700">Think about what you'd like to see and ask</p>
                      </div>
                    </div>
                    <div className="flex items-start gap-3">
                      <div className="w-6 h-6 rounded-full bg-blue-600 text-white flex items-center justify-center text-sm font-bold">3</div>
                      <div>
                        <p className="font-body font-medium text-blue-900">Arrive on Time</p>
                        <p className="font-body text-sm text-blue-700">Plan to arrive 10 minutes early</p>
                      </div>
                    </div>
                  </div>
                </CardContent>
              </AnimatedCard>
            </div>
          </div>

          {/* Navigation */}
          <div className="mt-12 flex flex-col sm:flex-row gap-4 justify-center">
            <Link href="/search">
              <AnimatedButton variant="outline" className="border-[#3F5CEA] text-[#3F5CEA] hover:bg-[#3F5CEA] hover:text-white">
                <ArrowRight className="h-4 w-4 mr-2" />
                Continue Searching
              </AnimatedButton>
            </Link>
            <Link href="/">
              <Button variant="outline" className="border-gray-300 text-gray-700 hover:bg-gray-50">
                <Home className="h-4 w-4 mr-2" />
                Back to Home
              </Button>
            </Link>
          </div>
        </div>
      </div>

      <Footer />
    </div>
  )
}
