import type { IntlShape } from "react-intl"

import type { Room } from "@/types/hotel"

export function getBedDescriptionText(
  intl: IntlShape,
  bed: Room["roomTypes"][number]["mainBed"]
) {
  const { type, widthRange, description } = bed
  const isCustomOccupancy = type === "CustomOccupancy"

  if (isCustomOccupancy) {
    return description
  }

  const mainBedWidthText = intl.formatMessage(
    { defaultMessage: "{value} cm" },
    { value: widthRange.min }
  )
  const mainBedWidthRangeText = intl.formatMessage(
    { defaultMessage: "{min}–{max} cm" },
    { min: widthRange.min, max: widthRange.max }
  )
  const sameWidth = widthRange.min === widthRange.max
  const widthText = sameWidth ? mainBedWidthText : mainBedWidthRangeText

  return `${description} (${widthText})`
}
