161 lines
4.3 KiB
TypeScript
161 lines
4.3 KiB
TypeScript
import {
|
|
activities,
|
|
meetingsAndConferences,
|
|
restaurantAndBar,
|
|
wellnessAndExercise,
|
|
} from "@/constants/routes/hotelPageParams"
|
|
|
|
import { getIntl } from "@/i18n"
|
|
import { getLang } from "@/i18n/serverContext"
|
|
|
|
import {
|
|
type Facilities,
|
|
type FacilityCards,
|
|
FacilityEnum,
|
|
FacilityIds,
|
|
RestaurantHeadings,
|
|
} from "@/types/components/hotelPage/facilities"
|
|
import type { ImageVaultAsset } from "@/types/components/imageVault"
|
|
import type { Amenities, Facility } from "@/types/hotel"
|
|
import type { CardProps } from "@/components/TempDesignSystem/Card/card"
|
|
|
|
type ActivityCard = {
|
|
background_image?: ImageVaultAsset
|
|
scripted_title?: string
|
|
heading: string
|
|
body_text: string
|
|
cta_text: string
|
|
contentPage: { href: string }
|
|
}
|
|
|
|
export function setActivityCard(activitiesCard: ActivityCard): FacilityCards {
|
|
const lang = getLang()
|
|
const hasImage = activitiesCard.background_image
|
|
return [
|
|
{
|
|
id: activities[lang],
|
|
theme: hasImage ? "image" : "primaryDark",
|
|
scriptedTopTitle: activitiesCard.scripted_title,
|
|
heading: activitiesCard.heading,
|
|
bodyText: activitiesCard.body_text,
|
|
backgroundImage: hasImage ? activitiesCard.background_image : undefined,
|
|
primaryButton: hasImage
|
|
? {
|
|
href: activitiesCard.contentPage.href,
|
|
title: activitiesCard.cta_text,
|
|
isExternal: false,
|
|
}
|
|
: undefined,
|
|
secondaryButton: hasImage
|
|
? undefined
|
|
: {
|
|
href: activitiesCard.contentPage.href,
|
|
title: activitiesCard.cta_text,
|
|
isExternal: false,
|
|
},
|
|
},
|
|
]
|
|
}
|
|
|
|
async function setCardProps(
|
|
theme: CardProps["theme"],
|
|
heading: string,
|
|
buttonText: string,
|
|
href: string
|
|
) {
|
|
const intl = await getIntl()
|
|
const card: CardProps = {}
|
|
|
|
card.theme = theme
|
|
card.id = href
|
|
card.heading = intl.formatMessage({ id: heading })
|
|
card.secondaryButton = {
|
|
href: `?s=${href}`,
|
|
title: intl.formatMessage({ id: buttonText }),
|
|
isExternal: false,
|
|
}
|
|
return card
|
|
}
|
|
|
|
export function setFacilityCards(facilities: Facility[], amenities: Amenities) {
|
|
const lang = getLang()
|
|
const cards: Facilities = []
|
|
|
|
facilities.forEach(async (facility) => {
|
|
const grid: Array<CardProps> = []
|
|
let card: CardProps = {}
|
|
|
|
facility.heroImages.slice(0, 2).forEach((image) => {
|
|
// Can be a maximum 2 images per grid
|
|
const img: CardProps = {}
|
|
;(img.backgroundImage = {
|
|
url: image.imageSizes.large,
|
|
title: image.metaData.title,
|
|
meta: {
|
|
alt: image.metaData.altText,
|
|
caption: image.metaData.altText_En,
|
|
},
|
|
}),
|
|
(img.theme = "image")
|
|
grid.push(img)
|
|
})
|
|
|
|
switch (facility.id) {
|
|
case FacilityEnum.wellness:
|
|
card = await setCardProps(
|
|
"one",
|
|
"Sauna and gym",
|
|
"Read more about wellness & exercise",
|
|
wellnessAndExercise[lang]
|
|
)
|
|
card.scriptedTopTitle = facility.headingText
|
|
grid.unshift(card)
|
|
break
|
|
|
|
case FacilityEnum.conference:
|
|
card = await setCardProps(
|
|
"primaryDim",
|
|
"Events that make an impression",
|
|
"About meetings & conferences",
|
|
meetingsAndConferences[lang]
|
|
)
|
|
card.scriptedTopTitle = facility.headingText
|
|
grid.push(card)
|
|
break
|
|
|
|
case FacilityEnum.restaurant:
|
|
//const title = getRestaurantHeading(amenities) // TODO will be used later
|
|
card = await setCardProps(
|
|
"primaryDark",
|
|
"Enjoy relaxed restaurant experiences",
|
|
"Read more & book a table",
|
|
restaurantAndBar[lang]
|
|
)
|
|
card.scriptedTopTitle = facility.headingText
|
|
grid.unshift(card)
|
|
break
|
|
}
|
|
cards.push(grid)
|
|
})
|
|
return cards
|
|
}
|
|
|
|
export function getRestaurantHeading(amenities: Amenities): RestaurantHeadings {
|
|
const hasBar = amenities.some(
|
|
(facility) =>
|
|
facility.id == FacilityIds.bar || facility.id == FacilityIds.rooftopBar
|
|
)
|
|
const hasRestaurant = amenities.some(
|
|
(facility) => facility.id == FacilityIds.restaurant
|
|
)
|
|
|
|
if (hasBar && hasRestaurant) {
|
|
return RestaurantHeadings.restaurantAndBar
|
|
} else if (hasBar) {
|
|
return RestaurantHeadings.bar
|
|
} else if (hasRestaurant) {
|
|
return RestaurantHeadings.restaurant
|
|
}
|
|
return RestaurantHeadings.breakfastRestaurant
|
|
}
|