import { dt } from "@scandic-hotels/common/dt" import type { IntlShape } from "react-intl" export const DAYS_UNTIL_EXPIRY_WARNING = 30 /** * Get expiry label for points based on the expiry date. * @returns The formatted expiry date text or empty string if no expiry date */ export function getExpiryLabel( pointsExpiryDate: string | undefined, intl: IntlShape, lang: string ): string { if (!pointsExpiryDate) { return "" } const now = dt() const expiryDate = dt(pointsExpiryDate).locale(lang) const daysUntilExpiry = expiryDate.diff(now, "days") if (daysUntilExpiry <= DAYS_UNTIL_EXPIRY_WARNING) { return intl.formatMessage( { id: "points.pointsToSpendCard.inDays", defaultMessage: "In {days} days", }, { days: daysUntilExpiry, } ) } else { return intl.formatMessage( { id: "points.pointsToSpendCard.onDate", defaultMessage: "on {expiryDate}", }, { expiryDate: expiryDate.format("DD MMM YYYY"), } ) } }