import { getIntl } from "@/i18n"

import { truncateTextAfterLastPeriod } from "../truncate"

import type { RawMetadataSchema } from "@/types/trpc/routers/contentstack/metadata"

export async function getDestinationCityPageDescription(
  data: RawMetadataSchema
) {
  const intl = await getIntl()

  if (!data.destinationData || !data.destinationData.hotelCount) {
    return null
  }

  const { hotelCount, location } = data.destinationData

  if (hotelCount === 1) {
    const destinationCitySingleHotelDescription = intl.formatMessage(
      {
        defaultMessage:
          "Discover our Scandic hotel in {location}. Start your day with a delicious breakfast before exploring {location}. Book your stay at a Scandic hotel now!",
      },
      {
        location: location,
      }
    )

    return truncateTextAfterLastPeriod(destinationCitySingleHotelDescription)
  }
  const destinationCityMultipleHotelDescription = intl.formatMessage(
    {
      defaultMessage:
        "Discover all our {hotelCount} Scandic hotels in {location}. Start your day with a delicious breakfast before exploring {location}. Book your stay at a Scandic hotel now!",
    },
    {
      hotelCount: hotelCount,
      location: location,
    }
  )

  return truncateTextAfterLastPeriod(destinationCityMultipleHotelDescription)
}
