import { getServerSession } from "next-auth"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { getAnnonceByIdInclude } from "@/lib/services/annonceService"; import Link from "next/link"; import ImageCarrousel from "@/lib/components/ImageCarrousel"; import AddQuestionButton from "@/lib/components/addQuestionButtonComponent"; import AnswerQuestionButton from "@/lib/components/answerQuestionButtonComponent"; export default async function AnnonceDetail({ params }: { params: { id: string } }) { const session = await getServerSession(authOptions); const annonce = await getAnnonceByIdInclude(Number(params.id)); if (!annonce) return
Annonce non trouvée.
; const agent = annonce.agent; const formattedPrice = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR", minimumFractionDigits: 0, }).format(annonce.price); const imageSrc = annonce.mainImg ? `data:image/jpeg;base64,${annonce.mainImg}` : "/default-image-annonce.jpg"; let imagesSrc = []; if (annonce.gallery && annonce.gallery.length > 0) { const autresImagesSrc = annonce.gallery.map((img) => `data:image/jpeg;base64,${img.imageData}`); imagesSrc = [imageSrc, ...autresImagesSrc]; } else { imagesSrc = [imageSrc]; } return (
← Retour aux annonces
{/* Colonne principale (Image et Description) */}
{/* Carrousel */}
{/* Titre et Adresse */}

{annonce.title}

{annonce.address}, {annonce.city}

{/* Description */}

Description

{annonce.description || "Aucune description."}

{/* Prix et Agent */}

FAQ

{annonce.questions && annonce.questions.length > 0 ? (
{annonce.questions.map((q) => (

đź’¬{" "} {q.authorName ?? "Utilisateur anonyme"} :

{q.content}

{q.answer ? ( <>

Réponse :

{q.answer}

— {q.answerAuthorName ?? "Agent"} le{" "} {q.answeredAt ? new Date(q.answeredAt).toLocaleDateString() : ""}

) : ( <>

Pas encore de réponse.

{session && (session.user?.role === "ADMIN" || Number(session.user?.id) === annonce.agent.id) && ( )} )}
))}
) : (

Aucune question posée pour le moment.

)} {session && }
); }