import { notFound } from "next/navigation"; import { getServerSession } from "next-auth"; import Link from "next/link"; import { authOptions } from "@/lib/auth"; import { tripService } from "@/server/services/trip.service"; import { formatRupiah, formatDate } from "@/lib/utils"; import { JoinTripButton } from "@/features/trip/components/join-trip-button"; import { ImageGallery } from "@/features/trip/components/image-gallery"; export default async function TripDetailPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; const session = await getServerSession(authOptions); let trip; try { trip = await tripService.getTripById(id); } catch { notFound(); } const activeParticipants = trip.participants.filter( (p) => p.status !== "CANCELLED" ); const participantCount = activeParticipants.length; const spotsLeft = trip.maxParticipants - participantCount; const fillPercent = Math.min( (participantCount / trip.maxParticipants) * 100, 100 ); const isOrganizer = session?.user?.id === trip.organizerId; const currentParticipation = session?.user ? trip.participants.find( (p) => p.userId === session.user.id && p.status !== "CANCELLED" ) : null; return (
{/* Breadcrumb */}
Open Trip / {trip.mountain}
{/* Image Gallery */} {/* Title bar */}

{trip.title}

🏔️ {trip.mountain}

{trip.status}
{/* Info Grid */}
📍

Lokasi

{trip.location}

📅

Tanggal

{formatDate(trip.date)}

💰

Harga

{formatRupiah(trip.price)}

👤

Organizer

{trip.organizer.name}

{/* Participant Progress */}
Peserta {participantCount}{" "} / {trip.maxParticipants}
= 100 ? "bg-amber-500" : fillPercent >= 70 ? "bg-secondary-500" : "bg-primary-500" }`} style={{ width: `${fillPercent}%` }} />

{spotsLeft > 0 ? `${spotsLeft} slot tersisa — yuk gabung!` : "Trip sudah penuh"}

{/* Description */} {trip.description && (

Deskripsi Trip

{trip.description}

)} {/* Action */} {/* Participants List */}

Peserta ({participantCount})

{participantCount === 0 ? (

Belum ada peserta. Jadilah yang pertama! 🎒

) : (
{activeParticipants.map((p) => (
{p.user.name.charAt(0).toUpperCase()}
{p.user.name}
))}
)}
); }