| 1 |
/** |
| 2 |
* Trip meal_plan field: canonical slugs and translated labels (admin + consistency with PHP). |
| 3 |
*/ |
| 4 |
import { __ } from "./i18n"; |
| 5 |
|
| 6 |
export type MealPlanSlug = |
| 7 |
| "" |
| 8 |
| "breakfast" |
| 9 |
| "half_board" |
| 10 |
| "full_board" |
| 11 |
| "all_inclusive" |
| 12 |
| "none"; |
| 13 |
|
| 14 |
/** Options for <select> (value + translated label). */ |
| 15 |
export const MEAL_PLAN_SELECT_OPTIONS: { |
| 16 |
value: MealPlanSlug; |
| 17 |
label: string; |
| 18 |
}[] = [ |
| 19 |
{ value: "", label: __("Select meal plan", "yatra") }, |
| 20 |
{ value: "breakfast", label: __("Breakfast Only", "yatra") }, |
| 21 |
{ |
| 22 |
value: "half_board", |
| 23 |
label: __("Half Board (Breakfast + Dinner)", "yatra"), |
| 24 |
}, |
| 25 |
{ value: "full_board", label: __("Full Board (All Meals)", "yatra") }, |
| 26 |
{ value: "all_inclusive", label: __("All Inclusive", "yatra") }, |
| 27 |
{ value: "none", label: __("No Meals Included", "yatra") }, |
| 28 |
]; |
| 29 |
|
| 30 |
/** Normalize legacy or odd casing to canonical slug key (underscore form). */ |
| 31 |
export function normalizeMealPlanSlug(raw: string): string { |
| 32 |
return String(raw || "") |
| 33 |
.trim() |
| 34 |
.toLowerCase() |
| 35 |
.replace(/[\s-]+/g, "_"); |
| 36 |
} |
| 37 |
|
| 38 |
/** Translated label for a stored slug, or title-cased fallback for unknown values. */ |
| 39 |
export function getMealPlanLabel(raw: string): string { |
| 40 |
const key = normalizeMealPlanSlug(raw) as MealPlanSlug; |
| 41 |
const row = MEAL_PLAN_SELECT_OPTIONS.find((o) => o.value === key); |
| 42 |
if (row) { |
| 43 |
return row.label; |
| 44 |
} |
| 45 |
if (!key) { |
| 46 |
return ""; |
| 47 |
} |
| 48 |
return key |
| 49 |
.split("_") |
| 50 |
.map((p) => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()) |
| 51 |
.join(" "); |
| 52 |
} |
| 53 |
|