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 } from '../../../lib/listings'; import { resolveLocale, t as translate } from '../../../lib/i18n'; type ListingPageProps = { params: { slug: string }; }; 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 translation = await getListingBySlug({ slug: params.slug, locale: locale ?? DEFAULT_LOCALE }); if (!translation) { notFound(); } const { listing, title, description, teaser, locale: translationLocale } = translation; return (
{t('homeCrumb')} / {params.slug}

{title}

{teaser ?? description}

{t('listingAddress')}: {listing.streetAddress ? `${listing.streetAddress}, ` : ''} {listing.city}, {listing.region}, {listing.country}
{listing.addressNote ? (
{listing.addressNote}
) : null}
{t('listingCapacity')}: {t('capacityGuests', { count: listing.maxGuests })} - {t('capacityBedrooms', { count: listing.bedrooms })} -{' '} {t('capacityBeds', { count: listing.beds })} - {t('capacityBathrooms', { count: listing.bathrooms })}
{t('listingAmenities')}:{' '} {[ listing.hasSauna && t('amenitySauna'), listing.hasFireplace && t('amenityFireplace'), listing.hasWifi && t('amenityWifi'), listing.petsAllowed && t('amenityPets'), listing.byTheLake && t('amenityLake'), listing.hasAirConditioning && t('amenityAirConditioning'), listing.evCharging === 'FREE' && t('amenityEvFree'), listing.evCharging === 'PAID' && t('amenityEvPaid'), ] .filter(Boolean) .join(', ') || '-'}
{t('listingContact')}: {listing.contactName} - {listing.contactEmail} {listing.contactPhone ? ` - ${listing.contactPhone}` : ''} {listing.externalUrl ? ( <> {' - '} {t('listingMoreInfo')} ) : null}
{listing.images.length > 0 ? (
{listing.images.map((img) => (
{img.altText {img.altText ? (
{img.altText}
) : null}
))}
) : null}
{t('localeLabel')}: {translationLocale}
); }