import { type BreadcrumbItem, type SharedData } from '@/types';
import { Head, Link, usePage } from '@inertiajs/react';
import { useLaravelReactI18n } from 'laravel-react-i18n';
import AppLayout from '@/layouts/app-layout';
import AiTouristGuide from '@/components/ai-tourist-guide';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { 
    MapPin, 
    Star, 
    Clock, 
    Users, 
    Euro, 
    Calendar,
    MessageCircle,
    Heart,
    Share2,
    Camera,
    Award,
    ChefHat,
    BookOpen,
    MapIcon
} from 'lucide-react';

interface Experience {
    id: number;
    name: string;
    description: string;
    image_url: string;
    category: string;
    rating: number;
    price: string;
    duration: string;
    location: string;
    created_at: string;
    updated_at: string;
    created_by_user: {
        id: number;
        name: string;
    };
}

interface ShowProps {
    experience: Experience;
}

const breadcrumbs: BreadcrumbItem[] = [
    {
        title: 'Home',
        href: '/',
    },
    {
        title: 'Experiences',
        href: '/experiences',
    },
    {
        title: 'Experience Details',
        href: '#',
    },
];

export default function Show({ experience }: ShowProps) {
    const { auth } = usePage<SharedData>().props;
    const { t } = useLaravelReactI18n();

    const similarExperiences = [
        {
            id: 2,
            image: 'https://images.unsplash.com/photo-1522202176988-66273c2fd55f?w=300&h=200&fit=crop&crop=center',
            title: 'Historical Paris Walking Tour',
            category: 'Cultural',
            rating: 4.8,
            price: '�45',
            duration: '2.5 hours'
        },
        {
            id: 3,
            image: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=300&h=200&fit=crop&crop=center',
            title: 'Sunset Seine River Cruise',
            category: 'Adventure',
            rating: 4.7,
            price: '�65',
            duration: '1.5 hours'
        }
    ];

    return (
        <AppLayout breadcrumbs={breadcrumbs}>
            <Head title={`${experience.name} - Smartsense Experiences`} />
            
            <div className="min-h-screen bg-gradient-to-b from-blue-50/30 via-white to-white dark:from-blue-950/20 dark:via-background dark:to-background">
                
                {/* Hero Section */}
                <section className="px-4 pt-6 lg:pt-8 mx-auto max-w-[1400px] w-full">
                    <div className="grid gap-6 lg:gap-12 lg:grid-cols-12">
                        {/* Image Gallery */}
                        <div className="lg:col-span-7">
                            <div className="relative aspect-[4/3] lg:aspect-[16/10] overflow-hidden rounded-2xl lg:rounded-3xl shadow-2xl">
                                <img 
                                    src={experience.image_url || 'https://images.unsplash.com/photo-1556909114-f6e7ad7d3136?w=1200&h=800&fit=crop&crop=center'}
                                    alt={experience.name}
                                    className="w-full h-full object-cover hover:scale-105 transition-transform duration-700"
                                    onError={(e) => {
                                        const target = e.target as HTMLImageElement;
                                        target.src = 'https://images.unsplash.com/photo-1556909114-f6e7ad7d3136?w=1200&h=800&fit=crop&crop=center';
                                    }}
                                />
                                <div className="absolute inset-0 bg-gradient-to-t from-black/30 via-transparent to-transparent" />
                                
                                {/* Action Buttons Overlay */}
                                <div className="absolute top-4 right-4 flex gap-2">
                                    <Button size="sm" variant="outline" className="bg-white/95 backdrop-blur-sm border-0 shadow-lg hover:bg-white">
                                        <Heart className="h-4 w-4" />
                                    </Button>
                                    <Button size="sm" variant="outline" className="bg-white/95 backdrop-blur-sm border-0 shadow-lg hover:bg-white">
                                        <Share2 className="h-4 w-4" />
                                    </Button>
                                </div>
                                
                                {/* Category Badge */}
                                <Badge className="absolute top-4 left-4 bg-gradient-to-r from-blue-600 to-purple-600 text-white shadow-lg backdrop-blur-sm border-0 px-3 py-1.5 text-sm font-medium">
                                    <ChefHat className="h-3 w-3 mr-1" />
                                    {t(experience.category)}
                                </Badge>
                                
                                {/* Photo Count */}
                                <div className="absolute bottom-4 right-4 bg-black/70 text-white px-3 py-1.5 rounded-full text-sm font-medium backdrop-blur-sm">
                                    <Camera className="h-4 w-4 inline mr-1" />
                                    {Math.floor(Math.random() * 50) + 10} photos
                                </div>
                            </div>
                        </div>

                        {/* Content */}
                        <div className="lg:col-span-5 flex flex-col justify-center space-y-6">
                            <div className="space-y-4">
                                <div className="flex items-start justify-between gap-4">
                                    <h1 className="text-2xl sm:text-3xl lg:text-4xl font-bold text-foreground leading-tight">
                                        {t(experience.name)}
                                    </h1>
                                    <div className="hidden lg:flex gap-2 shrink-0">
                                        <Button size="sm" variant="outline" className="gap-2">
                                            <Heart className="h-4 w-4" />
                                            {t('Save')}
                                        </Button>
                                        <Button size="sm" variant="outline" className="gap-2">
                                            <Share2 className="h-4 w-4" />
                                            {t('Share')}
                                        </Button>
                                    </div>
                                </div>
                                
                                {/* Rating & Location */}
                                <div className="flex flex-col sm:flex-row sm:items-center gap-3">
                                    <div className="flex items-center gap-2">
                                        <div className="flex items-center gap-1">
                                            <Star className="h-5 w-5 fill-yellow-400 text-yellow-400" />
                                            <Star className="h-5 w-5 fill-yellow-400 text-yellow-400" />
                                            <Star className="h-5 w-5 fill-yellow-400 text-yellow-400" />
                                            <Star className="h-5 w-5 fill-yellow-400 text-yellow-400" />
                                            <Star className="h-5 w-5 fill-yellow-400 text-yellow-400" />
                                            <span className="ml-1 font-semibold text-foreground">{experience.rating}</span>
                                        </div>
                                        <span className="text-sm text-muted-foreground">({Math.floor(Math.random() * 200) + 50} {t('reviews')})</span>
                                    </div>
                                    <div className="flex items-center gap-2 text-muted-foreground">
                                        <MapPin className="h-4 w-4" />
                                        <span className="text-sm font-medium">{experience.location}</span>
                                    </div>
                                </div>

                                <p className="text-muted-foreground leading-relaxed">
                                    {t(experience.description)}
                                </p>
                            </div>

                            {/* Quick Info Cards */}
                            <div className="grid gap-3 sm:grid-cols-2">
                                <Card className="border-0 shadow-md hover:shadow-lg transition-shadow duration-200">
                                    <CardContent className="p-4">
                                        <div className="flex items-center gap-3">
                                            <div className="p-2.5 rounded-xl bg-gradient-to-br from-blue-500 to-purple-600">
                                                <Euro className="h-5 w-5 text-white" />
                                            </div>
                                            <div className="flex-1">
                                                <p className="font-semibold text-foreground text-sm">{experience.price}</p>
                                                <p className="text-sm text-muted-foreground">{t('Per Person')}</p>
                                            </div>
                                        </div>
                                    </CardContent>
                                </Card>

                                <Card className="border-0 shadow-md hover:shadow-lg transition-shadow duration-200">
                                    <CardContent className="p-4">
                                        <div className="flex items-center gap-3">
                                            <div className="p-2.5 rounded-xl bg-gradient-to-br from-green-500 to-emerald-600">
                                                <Clock className="h-5 w-5 text-white" />
                                            </div>
                                            <div className="flex-1">
                                                <p className="font-semibold text-foreground text-sm">{experience.duration}</p>
                                                <p className="text-sm text-muted-foreground">{t('Duration')}</p>
                                            </div>
                                        </div>
                                    </CardContent>
                                </Card>
                            </div>

                            {/* Action Buttons */}
                            <div className="flex flex-col sm:flex-row gap-3 pt-2">
                                <Button size="lg" className="flex-1 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 gap-2">
                                    <Calendar className="h-4 w-4" />
                                    {t('Book Experience')}
                                </Button>
                                <Button variant="outline" size="lg" className="flex-1 gap-2">
                                    <MessageCircle className="h-4 w-4" />
                                    {t('Contact Host')}
                                </Button>
                            </div>
                        </div>
                    </div>
                </section>

                <div className="px-4 py-8 mx-auto max-w-[1400px] w-full">
                    <div className="grid gap-8 lg:grid-cols-3">
                        
                        {/* Main Content */}
                        <div className="lg:col-span-2 space-y-8">
                            
                            {/* Quick Info */}
                            <div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
                                <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                    <CardContent className="p-4 text-center">
                                        <div className="flex justify-center mb-2">
                                            <div className="p-2 rounded-xl bg-gradient-to-br from-blue-500 to-purple-600">
                                                <Euro className="h-5 w-5 text-white" />
                                            </div>
                                        </div>
                                        <p className="text-lg font-bold text-foreground">{experience.price}</p>
                                        <p className="text-sm text-muted-foreground">{t('Per Person')}</p>
                                    </CardContent>
                                </Card>
                                
                                <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                    <CardContent className="p-4 text-center">
                                        <div className="flex justify-center mb-2">
                                            <div className="p-2 rounded-xl bg-gradient-to-br from-green-500 to-emerald-600">
                                                <Clock className="h-5 w-5 text-white" />
                                            </div>
                                        </div>
                                        <p className="text-lg font-bold text-foreground">{experience.duration}</p>
                                        <p className="text-sm text-muted-foreground">{t('Duration')}</p>
                                    </CardContent>
                                </Card>
                                
                                <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm col-span-2 lg:col-span-1">
                                    <CardContent className="p-4 text-center">
                                        <div className="flex justify-center mb-2">
                                            <div className="p-2 rounded-xl bg-gradient-to-br from-orange-500 to-red-600">
                                                <Users className="h-5 w-5 text-white" />
                                            </div>
                                        </div>
                                        <p className="text-lg font-bold text-foreground">2-8</p>
                                        <p className="text-sm text-muted-foreground">{t('Group Size')}</p>
                                    </CardContent>
                                </Card>
                            </div>

                            {/* Description */}
                            <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                <CardContent className="p-6">
                                    <h2 className="text-xl font-bold text-foreground mb-4">{t('About This Experience')}</h2>
                                    <p className="text-muted-foreground leading-relaxed mb-4">
                                        {t(experience.description)}
                                    </p>
                                    <p className="text-muted-foreground leading-relaxed">
                                        {t('Join us for an unforgettable culinary journey where you\'ll learn the secrets of French pastry making from a professional chef. This hands-on workshop takes place in a beautiful Parisian kitchen where you\'ll create delicious pastries while learning about French culinary traditions.')}
                                    </p>
                                </CardContent>
                            </Card>

                            {/* What's Included */}
                            <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                <CardContent className="p-6">
                                    <h2 className="text-xl font-bold text-foreground mb-4">{t('What\'s Included')}</h2>
                                    <div className="grid gap-3 sm:grid-cols-2">
                                        {[
                                            'Professional chef instruction',
                                            'All ingredients and equipment',
                                            'Recipe cards to take home',
                                            'Light refreshments',
                                            'Certificate of completion',
                                            'Small group setting'
                                        ].map((item, index) => (
                                            <div key={index} className="flex items-center gap-3">
                                                <div className="w-2 h-2 rounded-full bg-gradient-to-r from-blue-600 to-purple-600" />
                                                <span className="text-muted-foreground">{t(item)}</span>
                                            </div>
                                        ))}
                                    </div>
                                </CardContent>
                            </Card>

                            {/* Meeting Point */}
                            <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                <CardContent className="p-6">
                                    <h2 className="text-xl font-bold text-foreground mb-4">{t('Meeting Point')}</h2>
                                    <div className="flex items-start gap-4">
                                        <div className="p-2 rounded-xl bg-gradient-to-br from-blue-500 to-purple-600">
                                            <MapIcon className="h-5 w-5 text-white" />
                                        </div>
                                        <div>
                                            <h3 className="font-semibold text-foreground mb-1">{t('Chef Marie\'s Culinary Studio')}</h3>
                                            <p className="text-muted-foreground mb-2">15 Rue de la Paix, 75001 Paris, France</p>
                                            <p className="text-sm text-muted-foreground">
                                                {t('Located just 5 minutes walk from Op�ra metro station. Look for the blue door with our studio sign.')}
                                            </p>
                                        </div>
                                    </div>
                                </CardContent>
                            </Card>
                        </div>

                        {/* Sidebar */}
                        <div className="space-y-6">
                            
                            {/* Booking Card */}
                            <Card className="border-0 shadow-lg bg-white/80 backdrop-blur-sm">
                                <CardContent className="p-6">
                                    <div className="text-center mb-6">
                                        <p className="text-3xl font-bold text-foreground mb-2">{experience.price}</p>
                                        <p className="text-muted-foreground">{t('per person')}</p>
                                    </div>
                                    
                                    <Button 
                                        size="lg" 
                                        className="w-full bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 mb-4"
                                    >
                                        <Calendar className="h-5 w-5 mr-2" />
                                        {t('Book Now')}
                                    </Button>
                                    
                                    <Button variant="outline" size="lg" className="w-full">
                                        <MessageCircle className="h-5 w-5 mr-2" />
                                        {t('Contact Host')}
                                    </Button>
                                    
                                    <div className="mt-4 pt-4 border-t text-center">
                                        <p className="text-sm text-muted-foreground">{t('Free cancellation up to 24 hours')}</p>
                                    </div>
                                </CardContent>
                            </Card>

                            {/* Host Information */}
                            <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                <CardContent className="p-6">
                                    <h3 className="text-lg font-bold text-foreground mb-4">{t('Your Host')}</h3>
                                    <div className="flex items-start gap-4">
                                        <Avatar className="h-12 w-12">
                                            <AvatarImage src="https://images.unsplash.com/photo-1494790108755-2616b612b977?w=100&h=100&fit=crop&crop=center" />
                                            <AvatarFallback>MD</AvatarFallback>
                                        </Avatar>
                                        <div>
                                            <h4 className="font-semibold text-foreground">{experience.created_by_user.name}</h4>
                                            <div className="flex items-center gap-2 text-sm text-muted-foreground mb-2">
                                                <Star className="h-4 w-4 fill-yellow-400 text-yellow-400" />
                                                <span>4.9</span>
                                                <span>�</span>
                                                <span>{t('127 reviews')}</span>
                                            </div>
                                            <p className="text-sm text-muted-foreground">
                                                {t('Professional pastry chef with 15+ years experience in Michelin-starred restaurants.')}
                                            </p>
                                        </div>
                                    </div>
                                    
                                    <div className="mt-4 pt-4 border-t">
                                        <div className="flex items-center gap-4 text-sm">
                                            <div className="flex items-center gap-1">
                                                <Award className="h-4 w-4 text-yellow-500" />
                                                <span className="text-muted-foreground">{t('Verified Host')}</span>
                                            </div>
                                            <div className="flex items-center gap-1">
                                                <BookOpen className="h-4 w-4 text-blue-500" />
                                                <span className="text-muted-foreground">{t('Expert Level')}</span>
                                            </div>
                                        </div>
                                    </div>
                                </CardContent>
                            </Card>

                            {/* Similar Experiences */}
                            <Card className="border-0 shadow-md bg-white/80 backdrop-blur-sm">
                                <CardContent className="p-6">
                                    <h3 className="text-lg font-bold text-foreground mb-4">{t('Similar Experiences')}</h3>
                                    <div className="space-y-4">
                                        {similarExperiences.map((exp) => (
                                            <Link key={exp.id} href={`/experiences/${exp.id}`} className="block group">
                                                <div className="flex gap-4 p-3 rounded-xl hover:bg-gray-50 transition-colors duration-200">
                                                    <div 
                                                        className="w-16 h-16 bg-cover bg-center rounded-lg flex-shrink-0"
                                                        style={{ backgroundImage: `url(${exp.image})` }}
                                                    />
                                                    <div className="flex-1 min-w-0">
                                                        <h4 className="font-semibold text-foreground text-sm group-hover:text-blue-600 transition-colors duration-200 line-clamp-2">
                                                            {t(exp.title)}
                                                        </h4>
                                                        <div className="flex items-center gap-2 mt-1">
                                                            <Badge variant="secondary" className="text-xs">{t(exp.category)}</Badge>
                                                            <div className="flex items-center gap-1">
                                                                <Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
                                                                <span className="text-xs text-muted-foreground">{exp.rating}</span>
                                                            </div>
                                                        </div>
                                                        <div className="flex items-center justify-between mt-2">
                                                            <span className="text-sm font-bold text-foreground">{exp.price}</span>
                                                            <span className="text-xs text-muted-foreground">{exp.duration}</span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </Link>
                                        ))}
                                    </div>
                                </CardContent>
                            </Card>
                        </div>
                    </div>
                </div>

                {/* AI Tourist Guide Component */}
                <AiTouristGuide pointOfInterestName={experience.name} />
            </div>
        </AppLayout>
    );
}