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, formatDateRange } 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 (
🏔️ {trip.mountain}
Lokasi
{trip.location}
Tanggal
{formatDateRange(trip.date, trip.endDate)}
Harga
{formatRupiah(trip.price)}
Organizer
{trip.organizer.name}
{spotsLeft > 0 ? `${spotsLeft} slot tersisa — yuk gabung!` : "Trip sudah penuh"}
{trip.description}
Belum ada peserta. Jadilah yang pertama! 🎒
) : (