import { getProfileSafely } from "@/lib/trpc/memoizedRequests"

import { SASLevelUpgradeCheck } from "@/components/MyPages/SASLevelUpgradeCheck"
import Surprises from "@/components/MyPages/Surprises"
import { getEurobonusMembership } from "@/utils/user"

import styles from "./layout.module.css"

export default async function MyPagesLayout({
  breadcrumbs,
  children,
}: React.PropsWithChildren<{
  breadcrumbs: React.ReactNode
}>) {
  const profile = await getProfileSafely()
  const eurobonusMembership = profile?.loyalty
    ? getEurobonusMembership(profile.loyalty)
    : null

  return (
    <div className={styles.container}>
      <div className={styles.layout}>
        {breadcrumbs}
        <div className={styles.content}>{children}</div>
      </div>

      {eurobonusMembership && <SASLevelUpgradeCheck />}
      <Surprises />
    </div>
  )
}
