import { cx } from "class-variance-authority" import Table from "@scandic-hotels/design-system/Table" import { TextLink } from "@scandic-hotels/design-system/TextLink" import { Typography } from "@scandic-hotels/design-system/Typography" import { getAllHotelData } from "@/lib/trpc/memoizedRequests" import { getIntl } from "@/i18n" import styles from "./rewardNights.module.css" import type { RewardNight } from "@scandic-hotels/trpc/types/hotel" export async function RewardNights() { const intl = await getIntl() const hotelData = await getAllHotelData() return ( {intl.formatMessage({ id: "rewardNights.table.hotel", defaultMessage: "Hotel", })} {intl.formatMessage({ id: "rewardNights.table.destination", defaultMessage: "Destination", })} {intl.formatMessage({ id: "common.points", defaultMessage: "Points", })} {hotelData.map((data) => { const { hotel } = data const hasCampaign = hasActiveCampaign(hotel.rewardNight.campaign) return ( {hotel.name} {/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} {`${hotel.address.city}, ${hotel.address.country}`} {hasCampaign ? ( ) : null}
{formatPoints(hotel.rewardNight.points)} {hasCampaign ? ( {formatPoints(hotel.rewardNight.campaign.points)} ) : null}
) })}
) } interface OfferPriceProps { points: number start: string end: string } async function OfferPrice(offer: OfferPriceProps) { const intl = await getIntl() return (

{intl.formatMessage({ id: "rewardNights.offerPrice", defaultMessage: "Offer price", })}

{intl.formatMessage({ id: "rewardNights.stayBetween:", defaultMessage: "Stay between:", })}

) } function formatPoints(number: number) { const format = new Intl.NumberFormat("fr-FR") return format.format(number).replace(/\u202F/g, " ") } function formatDate(date?: string) { return new Date(date ?? Date.now()).toISOString().split("T")[0] } function hasActiveCampaign(campaign: RewardNight["campaign"]) { return campaign.points && formatDate(campaign.end) >= formatDate() }