"use client" import { useReducer } from "react" import { useIntl } from "react-intl" import { type MembershipLevel } from "@scandic-hotels/common/constants/membershipLevels" import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect" import { membershipLevels } from "@/constants/membershipLevels" import MembershipLevelIcon from "@/components/Levels/Icon" import LargeTable from "./LargeTable" import LevelSummary from "./LevelSummary" import { getInitialState, getLevel, reducer } from "./reducer" import RewardList from "./RewardList" import YourLevel from "./YourLevelScript" import styles from "./overviewTable.module.css" import type { Key } from "react-aria-components" import { type ComparisonLevel, type DesktopSelectColumns, type MobileColumnHeaderProps, OverviewTableActionsEnum, type OverviewTableClientProps, } from "@/types/components/overviewTable" function getLevelNamesForSelect(level: MembershipLevel, levelName: string) { const levelToNumber = membershipLevels[level] return [levelToNumber, levelName].join(" ") } export default function OverviewTableClient({ activeMembership, levels, }: OverviewTableClientProps) { const intl = useIntl() const [selectionState, dispatch] = useReducer( reducer, { activeMembership, levels }, getInitialState ) function handleSelectChange(actionType: OverviewTableActionsEnum) { return (key: Key) => { dispatch({ payload: getLevel(key as MembershipLevel, levels), type: actionType, }) } } const levelOptions = levels.map((level) => ({ label: getLevelNamesForSelect(level.level_id, level.name), value: level.level_id, })) const activeMembershipLevel = activeMembership ?? null function MobileColumnHeader({ column }: MobileColumnHeaderProps) { let selectedLevelMobile: ComparisonLevel let actionEnumMobile: OverviewTableActionsEnum switch (column) { case "A": selectedLevelMobile = selectionState.selectedLevelAMobile actionEnumMobile = OverviewTableActionsEnum.SET_SELECTED_LEVEL_A_MOBILE break case "B": selectedLevelMobile = selectionState.selectedLevelBMobile actionEnumMobile = OverviewTableActionsEnum.SET_SELECTED_LEVEL_B_MOBILE break default: return null } return (