import { notFound } from "next/navigation"; import { Query } from "node-appwrite"; import { DATABASE_ID, TABLES, type Presentation, type Property } from "@/lib/appwrite/schema"; import { createAdminClient } from "@/lib/appwrite/server"; import { incrementPresentationViewCount } from "@/lib/appwrite/presentation-actions"; import { PROPERTY_TYPE_LABELS, LISTING_TYPE_LABELS, PROPERTY_STATUS_LABELS, } from "@/lib/appwrite/schema"; interface Props { params: Promise<{ token: string }>; } export default async function SunumPage({ params }: Props) { const { token } = await params; const { tablesDB } = createAdminClient(); const result = await tablesDB.listRows({ databaseId: DATABASE_ID, tableId: TABLES.presentations, queries: [Query.equal("shareToken", token), Query.limit(1)], }); if (!result.rows.length) notFound(); const presentation = result.rows[0] as unknown as Presentation; if (presentation.expiresAt && new Date(presentation.expiresAt) < new Date()) { return (

Sunum Süresi Doldu

Bu sunum artık geçerli değil.

); } // Increment view count (fire-and-forget) void incrementPresentationViewCount(presentation.$id, presentation.viewCount ?? 0); let propertyIds: string[] = []; try { propertyIds = JSON.parse(presentation.propertyIds) as string[]; } catch { propertyIds = []; } const properties: Property[] = []; for (const pid of propertyIds) { try { const row = await tablesDB.getRow(DATABASE_ID, TABLES.properties, pid); properties.push(row as unknown as Property); } catch { // Property may have been deleted } } return (

{presentation.title}

{presentation.notes && (

{presentation.notes}

)}

{properties.length} ilan

{properties.map((p) => ( ))} {properties.length === 0 && (

Bu sunumda ilan bulunmuyor.

)}
); } function PropertyCard({ property: p }: { property: Property }) { const isExpired = p.status === "satildi" || p.status === "kiralandit"; return (
🏠

{p.title}

{PROPERTY_STATUS_LABELS[p.status] ?? p.status}
{PROPERTY_TYPE_LABELS[p.propertyType] ?? p.propertyType} · {LISTING_TYPE_LABELS[p.listingType] ?? p.listingType} {p.roomCount && ( <> · {p.roomCount} )} {p.netM2 && ( <> · {p.netM2} m² )}

{[p.neighborhood, p.district, p.city].filter(Boolean).join(", ")}

{p.price.toLocaleString("tr-TR")} {p.currency ?? "TRY"}

{p.description && (

{p.description}

)}
); }