134 lines
3.4 KiB
TypeScript
134 lines
3.4 KiB
TypeScript
import {
|
|
meetingsAndConferences,
|
|
restaurantAndBar,
|
|
wellnessAndExercise,
|
|
} from "@/constants/routes/hotelPageParams"
|
|
|
|
import { getLang } from "@/i18n/serverContext"
|
|
|
|
import {
|
|
type Facilities,
|
|
type FacilityCard,
|
|
type FacilityCardType,
|
|
FacilityEnum,
|
|
type FacilityGrid,
|
|
FacilityIds,
|
|
type FacilityImage,
|
|
RestaurantHeadings,
|
|
} from "@/types/components/hotelPage/facilities"
|
|
import type { Amenities, Facility } from "@/types/hotel"
|
|
import type { CardProps } from "@/components/TempDesignSystem/Card/card"
|
|
|
|
export function isFacilityCard(card: FacilityCardType): card is FacilityCard {
|
|
return (card as FacilityCard).heading != undefined
|
|
}
|
|
|
|
export function isFacilityImage(card: FacilityCardType): card is FacilityCard {
|
|
return (card as FacilityImage).backgroundImage != undefined
|
|
}
|
|
|
|
function setCardProps(
|
|
theme: CardProps["theme"],
|
|
heading: string,
|
|
buttonText: string,
|
|
href: string,
|
|
scriptedTopTitle: string
|
|
): FacilityCard {
|
|
return {
|
|
theme: theme,
|
|
id: href,
|
|
heading: heading,
|
|
scriptedTopTitle: scriptedTopTitle,
|
|
secondaryButton: {
|
|
href: `?s=${href}`,
|
|
title: buttonText,
|
|
isExternal: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function setFacilityCardGrids(facilities: Facility[]): Facilities {
|
|
const lang = getLang()
|
|
const cards: Facilities = []
|
|
|
|
facilities.forEach(async (facility) => {
|
|
const grid: FacilityGrid = []
|
|
let card: FacilityCard
|
|
|
|
facility.heroImages.slice(0, 2).forEach((image) => {
|
|
// Can be a maximum 2 images per grid
|
|
const img: FacilityImage = {
|
|
backgroundImage: {
|
|
url: image.imageSizes.large,
|
|
title: image.metaData.title,
|
|
meta: {
|
|
alt: image.metaData.altText,
|
|
caption: image.metaData.altText_En,
|
|
},
|
|
id: image.imageSizes.large,
|
|
},
|
|
theme: "image",
|
|
id: image.imageSizes.large,
|
|
}
|
|
grid.push(img)
|
|
})
|
|
|
|
switch (facility.id) {
|
|
case FacilityEnum.wellness:
|
|
card = setCardProps(
|
|
"one",
|
|
"Sauna and gym",
|
|
"Read more about wellness & exercise",
|
|
wellnessAndExercise[lang],
|
|
facility.headingText
|
|
)
|
|
grid.unshift(card)
|
|
break
|
|
|
|
case FacilityEnum.conference:
|
|
card = setCardProps(
|
|
"primaryDim",
|
|
"Events that make an impression",
|
|
"About meetings & conferences",
|
|
meetingsAndConferences[lang],
|
|
facility.headingText
|
|
)
|
|
grid.push(card)
|
|
break
|
|
|
|
case FacilityEnum.restaurant:
|
|
//const title = getRestaurantHeading(amenities) // TODO will be used later
|
|
card = setCardProps(
|
|
"primaryDark",
|
|
"Enjoy relaxed restaurant experiences",
|
|
"Read more & book a table",
|
|
restaurantAndBar[lang],
|
|
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
|
|
}
|