"use client"
import FocusLock from "react-focus-lock"
import { useIntl } from "react-intl"
import Caption from "@scandic-hotels/design-system/Caption"
import { Divider } from "@scandic-hotels/design-system/Divider"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import Link from "@scandic-hotels/design-system/Link"
import Subtitle from "@scandic-hotels/design-system/Subtitle"
import { trpc } from "@scandic-hotels/trpc/client"
import { logout } from "@/constants/routes/handleAuth"
import useLang from "@/hooks/useLang"
import styles from "./myPagesMenuContent.module.css"
import type { MyPagesLinkKey } from "@scandic-hotels/trpc/routers/navigation/mypages/MyPagesLink"
import type { MyPagesMenuProps } from "../MyPagesMenu"
type Props = MyPagesMenuProps & { toggleOpenStateFn: () => void }
export default function MyPagesMenuContent({
membership,
toggleOpenStateFn,
user,
membershipLevel,
}: Props) {
const intl = useIntl()
const { data: myPagesNavigation } = useMyPagesNavigation()
const primaryLinks = myPagesNavigation?.primaryLinks ?? []
const secondaryLinks = myPagesNavigation?.secondaryLinks ?? []
const membershipPoints = membership?.currentPoints
const introClassName =
membershipLevel && membershipPoints
? `${styles.intro}`
: `${styles.intro} ${styles.noMembership}`
if (primaryLinks.length === 0 && secondaryLinks.length === 0) {
return null
}
return (
)
}
function PrimaryLinks({
toggleOpenStateFn,
}: {
toggleOpenStateFn: () => void
}) {
const { data: myPagesNavigation } = useMyPagesNavigation()
const primaryLinks = myPagesNavigation?.primaryLinks ?? []
return (
{primaryLinks.map((link, i) => (
-
{link.text}
))}
)
}
function SecondaryLinks({
toggleOpenStateFn,
}: {
toggleOpenStateFn: () => void
}) {
const intl = useIntl()
const lang = useLang()
const { data: myPagesNavigation } = useMyPagesNavigation()
const secondaryLinks = myPagesNavigation?.secondaryLinks ?? []
return (
{secondaryLinks.map((link, i) => (
-
{link.text}
))}
-
{intl.formatMessage({
defaultMessage: "Log out",
})}
)
}
export const useMyPagesNavigation = () => {
const lang = useLang()
const intl = useIntl()
const MyPagesLinkTranslationMap: Record = {
overview: intl.formatMessage({
defaultMessage: "Overview",
}),
points: intl.formatMessage({
defaultMessage: "My points",
}),
stays: intl.formatMessage({
defaultMessage: "My stays",
}),
benefits: intl.formatMessage({
defaultMessage: "My benefits",
}),
partnerSas: intl.formatMessage({
defaultMessage: "Scandic ♥ SAS",
}),
teamMemberCard: intl.formatMessage({
defaultMessage: "Team Member Card",
}),
scandicFriends: intl.formatMessage({
defaultMessage: "About Scandic Friends",
}),
profile: intl.formatMessage({
defaultMessage: "My profile",
}),
}
const result = trpc.navigation.myPages.useQuery({
lang: lang,
})
if (result.data) {
const primaryLinks = result.data.primaryLinks.map((link) => ({
...link,
text: MyPagesLinkTranslationMap[link.key],
}))
const secondaryLinks = result.data.secondaryLinks.map((link) => ({
...link,
text: MyPagesLinkTranslationMap[link.key],
}))
return { ...result, data: { primaryLinks, secondaryLinks } }
}
return { ...result, data: null }
}