import type { IntlShape } from "react-intl"

import type { CategorizedFilters } from "@/types/components/destinationFilterAndSort"

export function getHeadingText(
  intl: IntlShape,
  location: string,
  allFilters: CategorizedFilters,
  filter?: string
) {
  if (filter) {
    const facilityFilter = allFilters.facilityFilters.find(
      (f) => f.slug === filter
    )
    const surroudingsFilter = allFilters.surroundingsFilters.find(
      (f) => f.slug === filter
    )

    if (facilityFilter) {
      return intl.formatMessage(
        {
          defaultMessage: "Hotels with {filter} in {location}",
        },
        { location, filter: facilityFilter.name }
      )
    } else if (surroudingsFilter) {
      return intl.formatMessage(
        {
          defaultMessage: "Hotels near {filter} in {location}",
        },
        { location, filter: surroudingsFilter.name }
      )
    }
  }
  return intl.formatMessage(
    {
      defaultMessage: "Hotels in {location}",
    },
    { location }
  )
}
