"use client" import { Button } from "@/components/ui/button" import { Card } from "@/components/ui/card" import { Star, Clock, Users, ShieldCheck } from "lucide-react" import Link from "next/link" import { useLanguage } from "@/lib/language-context" import Image from "next/image" import { useEffect, useMemo, useState } from "react" const Hero = () => { const { t, language } = useLanguage() const [ratingsData, setRatingsData] = useState(null) const [featuredReview, setFeaturedReview] = useState(null) useEffect(() => { const fetchRatings = async () => { try { const response = await fetch(`/ratings_${language}.json`) const data = await response.json() setRatingsData(data) const reviews = data?.data?.[0]?.reviews ?? [] if (reviews.length > 0) { const randomIndex = Math.floor(Math.random() * reviews.length) setFeaturedReview(reviews[randomIndex]) } } catch (error) { console.error("Error fetching ratings:", error) } } fetchRatings() }, [language]) const ratingValue = ratingsData?.data?.[0]?.rating ?? 5.0 const ratingCount = ratingsData?.data?.[0]?.userRatingCount ?? 0 const ratingPercent = Math.max(0, Math.min(100, (ratingValue / 5) * 100)) const reviewAuthor = featuredReview?.author ?? t.hero.cards.reviewAuthor const reviewInitials = useMemo(() => { if (!reviewAuthor) return t.hero.cards.reviewInitial const initials = reviewAuthor .split(" ") .filter(Boolean) .slice(0, 2) .map((part: string) => part[0]?.toUpperCase()) .join("") return initials || t.hero.cards.reviewInitial }, [reviewAuthor, t.hero.cards.reviewInitial]) const reviewRating = Math.max(0, Math.min(5, Math.round(featuredReview?.rating ?? 5))) const reviewTextRaw = featuredReview?.text ?? t.hero.cards.reviewText const reviewText = reviewTextRaw.length > 120 ? `${reviewTextRaw.slice(0, 120).trimEnd()}...` : reviewTextRaw return (
{/* Background with diagonal slice */}
{ratingValue.toFixed(1)}/5.0
({ratingCount}) {t.hero.rating}

{t.hero.title}
{t.hero.titleAccent}

{t.hero.subtitle}

{t.hero.description}

{/* Main Floating Card - Booking Status */}
{t.hero.cards.activeBooking}
{t.hero.cards.fixedPrice}

{t.hero.cards.departure}

{t.hero.cards.fromCity}

{t.hero.cards.destination}

{t.hero.cards.toAirport}

{t.hero.cards.duration}

{t.hero.cards.passengers}

{t.hero.cards.insured}

{/* Overlapping small cards - Hidden on mobile, only visible from lg up */}
Family Travel
{t.hero.cards.familyTag}

{t.hero.cards.freeChildSeat}

{t.hero.cards.familyDesc}

Premium Fleet

{t.hero.cards.premiumFleet}

{t.hero.cards.mercedes}

{t.hero.cards.nonStop}
{t.hero.cards.supportTime}
{/* Review Snippet - Hidden on mobile, only visible from lg up */}
{[1, 2, 3, 4, 5].map((i) => ( ))}

{reviewText}

{reviewInitials}
{reviewAuthor}
) } export default Hero