type ImageDimensions = {
  width: number
  height: number
  orientation: 'portrait' | 'landscape' | 'portrait-upside-down' | 'landscape-left' | 'landscape-right'
}

/**
 * Calculates the height of an image based on the desired width and the image's dimensions.
 * The calculation takes into account the aspect ratio of the image into account and ensures that the calculated height
 * respects the aspect ratio.
 *
 * @param desiredWidth The width the image should have.
 * @param imageDimensions The dimensions and orientation of the image.
 */
export default function calculateImageHeight(desiredWidth: number, imageDimensions: ImageDimensions): number {
  const dimensions = {...imageDimensions}
  if (imageDimensions.orientation.includes('portrait')) {
    dimensions.width = imageDimensions.height
    dimensions.height = imageDimensions.width
  }

  const aspectRatio = dimensions.width / dimensions.height
  return Math.ceil(desiredWidth / aspectRatio)
}
