import type { Metadata } from 'next'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import { cookies, headers } from 'next/headers'; import { getListingBySlug, DEFAULT_LOCALE, withResolvedListingImages } from '../../../lib/listings'; import { SAMPLE_LISTING_SLUGS } from '../../../lib/sampleListing'; import { resolveLocale, t as translate } from '../../../lib/i18n'; type ListingPageProps = { params: { slug: string }; }; const amenityIcons: Record = { sauna: '🧖', fireplace: '🔥', wifi: '📶', pets: '🐾', lake: '🌊', ac: '❄️', ev: '⚡', }; export async function generateMetadata({ params }: ListingPageProps): Promise { const translation = await getListingBySlug({ slug: params.slug, locale: DEFAULT_LOCALE }); return { title: translation ? `${translation.title} | Lomavuokraus.fi` : `${params.slug} | Lomavuokraus.fi`, description: translation?.teaser ?? translation?.description?.slice(0, 140), }; } export default async function ListingPage({ params }: ListingPageProps) { const cookieStore = cookies(); const locale = resolveLocale({ cookieLocale: cookieStore.get('locale')?.value, acceptLanguage: headers().get('accept-language') }); const t = (key: any, vars?: Record) => translate(locale, key as any, vars); const translationRaw = await getListingBySlug({ slug: params.slug, locale: locale ?? DEFAULT_LOCALE }); const translation = translationRaw ? withResolvedListingImages(translationRaw) : null; if (!translation) { notFound(); } const { listing, title, description, teaser, locale: translationLocale } = translation; const isSample = listing.isSample || listing.contactEmail === 'host@lomavuokraus.fi' || SAMPLE_LISTING_SLUGS.includes(params.slug); const amenities = [ listing.hasSauna ? { icon: amenityIcons.sauna, label: t('amenitySauna') } : null, listing.hasFireplace ? { icon: amenityIcons.fireplace, label: t('amenityFireplace') } : null, listing.hasWifi ? { icon: amenityIcons.wifi, label: t('amenityWifi') } : null, listing.petsAllowed ? { icon: amenityIcons.pets, label: t('amenityPets') } : null, listing.byTheLake ? { icon: amenityIcons.lake, label: t('amenityLake') } : null, listing.hasAirConditioning ? { icon: amenityIcons.ac, label: t('amenityAirConditioning') } : null, listing.evCharging === 'FREE' ? { icon: amenityIcons.ev, label: t('amenityEvFree') } : null, listing.evCharging === 'PAID' ? { icon: amenityIcons.ev, label: t('amenityEvPaid') } : null, ].filter(Boolean) as { icon: string; label: string }[]; const addressLine = `${listing.streetAddress ? `${listing.streetAddress}, ` : ''}${listing.city}, ${listing.region}, ${listing.country}`; const capacityLine = `${t('capacityGuests', { count: listing.maxGuests })} · ${t('capacityBedrooms', { count: listing.bedrooms })} · ${t('capacityBeds', { count: listing.beds })} · ${t('capacityBathrooms', { count: listing.bathrooms })}`; const contactLine = `${listing.contactName} · ${listing.contactEmail}${listing.contactPhone ? ` · ${listing.contactPhone}` : ''}`; return (
{t('homeCrumb')} / {params.slug}
{isSample ? (
{t('sampleBadge')}
) : null}

{title}

{teaser ?? description}

{listing.addressNote ? (
{listing.addressNote}
) : null} {listing.externalUrl ? ( ) : null} {listing.images.length > 0 ? (
{listing.images .filter((img) => Boolean(img.url)) .map((img) => (
{img.altText {img.altText ? (
{img.altText}
) : null}
))}
) : null}
{t('localeLabel')}: {translationLocale}
); }