import { serverClient } from "@/lib/trpc/server"
import { PageTypes } from "@/server/routers/contentstack/breadcrumbs/input"

import { auth } from "@/auth"
import { Blocks } from "@/components/Loyalty/Blocks"
import SidebarLoyalty from "@/components/Loyalty/Sidebar"
import MaxWidth from "@/components/MaxWidth"
import Sidebar from "@/components/MyPages/Sidebar"

import Breadcrumbs from "../MyPages/Breadcrumbs"

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

import { LangParams } from "@/types/params"

export default async function LoyaltyPage({ lang }: LangParams) {
  const loyaltyPage = await serverClient().contentstack.loyaltyPage.get()
  const session = await auth()

  return (
    <>
      {session && <Breadcrumbs pageType={PageTypes.Loyalty} />}
      <section className={styles.content}>
        {session ? (
          <Sidebar lang={lang} />
        ) : loyaltyPage.sidebar.length ? (
          <SidebarLoyalty blocks={loyaltyPage.sidebar} />
        ) : null}

        <MaxWidth className={styles.blocks} tag="main">
          {loyaltyPage.blocks ? <Blocks blocks={loyaltyPage.blocks} /> : null}
        </MaxWidth>
      </section>
    </>
  )
}
