import { getTranslations, setRequestLocale } from 'next-intl/server'
import { mockDb } from '@/lib/mockDb'
import ListingCard from '@/components/ListingCard'
import { notFound } from 'next/navigation'
import Image from 'next/image'
import { Link } from '@/i18n/routing'
import { Phone, Globe, MapPin, Clock, Star, MessageSquare, Share2 } from 'lucide-react'
import SaveButton from './SaveButton'
interface DetailPageProps {
params: Promise<{ locale: string; category: string; slug: string }>
}
export async function generateMetadata({ params }: DetailPageProps) {
const { slug } = await params
const listing = await mockDb.getListingBySlug(slug)
if (!listing) return {}
return {
title: `${listing.nameTr} — Marmaris Local`,
description: listing.descriptionTr
}
}
export default async function ListingDetailPage({ params }: DetailPageProps) {
const { locale, category, slug } = await params
setRequestLocale(locale)
const t = await getTranslations('detail')
const listing = await mockDb.getListingBySlug(slug)
if (!listing) {
notFound()
}
// Fetch similar listings in same category (limit to 3, excluding current)
const allCategoryListings = await mockDb.getListings({
categoryId: listing.categoryId
})
const relatedListings = allCategoryListings
.filter(l => l.id !== listing.id)
.slice(0, 3)
// Fetch newest 3 listings (excluding current)
const allListings = await mockDb.getListings()
const latestListings = allListings
.filter(l => l.id !== listing.id)
.slice(0, 3)
// Fetch Instagram Feed Cache
const instagramFeed = await mockDb.getInstagramFeedCacheByListingId(listing.id)
const instagramPosts = instagramFeed?.posts ? (instagramFeed.posts as any[]) : []
// Localized values
const name =
locale === 'ru'
? listing.nameRu
: locale === 'en'
? listing.nameEn
: listing.nameTr
const description =
locale === 'ru'
? listing.descriptionRu
: locale === 'en'
? listing.descriptionEn
: listing.descriptionTr
const priceSymbols = '₺'.repeat(listing.priceRange)
const categorySlug = listing.category?.slug || 'isletme'
// Format WhatsApp Link
const getWhatsAppLink = (number: string) => {
const cleanNum = number.replace(/\D/g, '')
return `https://wa.me/${cleanNum}`
}
// WhatsApp Share deep link text
const getShareLink = () => {
const text = encodeURIComponent(`Marmaris Local'da harika bir yer keşfettim: ${name}\nDetayları incele: https://marmarislocal.com/${locale}/${categorySlug}/${listing.slug}`)
return `https://wa.me/?text=${text}`
}
return (
{/* Breadcrumb */}
marmaris local
/
{locale === 'ru' ? listing.category?.nameRu : locale === 'en' ? listing.category?.nameEn : listing.category?.nameTr}
/
{name}
{/* Hero Details Block */}
{/* Left: Gallery Panel */}
0 ? listing.images[0].url : 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'}
alt={name}
fill
priority
className="object-cover"
/>
{/* Thumbnails if multiple images exist */}
{listing.images && listing.images.length > 1 && (
{listing.images.slice(1, 5).map((img, idx) => (
))}
)}
{/* Right: Info Panel */}
{locale === 'ru' ? listing.category?.nameRu : locale === 'en' ? listing.category?.nameEn : listing.category?.nameTr}
{listing.isLocalApproved && (
★ {t('approved')}
)}
{name}
{/* Stars and Price level */}
{listing.rating && (
{t('rating')}: {listing.rating.toFixed(1)}
)}
{t('price')}: {priceSymbols}
{/* Description */}
{description}
{/* Contact & Actions Grid */}
{t('contact')}
{/* External links */}
{/* Details footer (Hours & Location map) */}
{/* Address */}
{t('address')}
{listing.address}
{/* Hours */}
{t('hours')}
{listing.openingHours ? (
{(listing.openingHours as any).all || t('noHours')}
) : (
{t('noHours')}
)}
{/* Map Frame */}
{listing.latitude && listing.longitude && (
)}
{/* Instagram Feed Cache (Phase 2) */}
{instagramFeed && instagramPosts.length > 0 && (
IG
@{instagramFeed.handle}
{t('instagramFeed')}
{instagramPosts.slice(0, 3).map((post: any, idx: number) => (
))}
)}
{/* Newly Added Widget (Phase 2) */}
{latestListings.length > 0 && (
{t('newlyAdded')}
{t('newlyAddedSubtitle')}
{latestListings.map((newest) => {
const catSlug = newest.category?.slug || 'isletmeler'
const newestName = locale === 'en' ? newest.nameEn : locale === 'ru' ? newest.nameRu : newest.nameTr
const newestImg = newest.images && newest.images.length > 0 ? newest.images[0].url : 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'
return (
{newestName}
{newest.neighborhood?.nameTr}
)
})}
)}
{/* Related Section */}
{relatedListings.length > 0 && (
{t('related')}
{relatedListings.map((listingItem) => (
))}
)}
)
}