Files
web/components/Blocks/HotelListing/HotelListingItem/utils.ts
2025-02-25 10:45:45 +01:00

37 lines
1.3 KiB
TypeScript

import type { Hotel } from "@/types/hotel"
import type { HotelListing } from "@/types/trpc/routers/contentstack/blocks"
export function getTypeSpecificInformation(
contentType: HotelListing["contentType"],
hotel: Hotel
) {
const { images } = hotel.hotelContent
const { descriptions, meetingDescription } = hotel.hotelContent.texts
const hotelData = {
description: descriptions?.short,
imageSrc: images.imageSizes.small,
altText: images.metaData.altText,
}
switch (contentType) {
case "meeting":
const meetingImage = hotel.conferencesAndMeetings?.heroImages[0]
return {
description: meetingDescription?.short || hotelData.description,
imageSrc: meetingImage?.imageSizes.small || hotelData.imageSrc,
altText: meetingImage?.metaData.altText || hotelData.altText,
}
case "restaurant":
const restaurantImage = hotel.restaurantImages?.heroImages[0]
return {
description:
hotel.hotelContent.restaurantsOverviewPage
.restaurantsContentDescriptionShort || hotelData.description,
imageSrc: restaurantImage?.imageSizes.small || hotelData.imageSrc,
altText: restaurantImage?.metaData.altText || hotelData.altText,
}
case "hotel":
default:
return hotelData
}
}