import { serverClient } from "@/lib/trpc/server"

import Content from "@/components/MyPages/AccountPage/Content"
import Title from "@/components/TempDesignSystem/Text/Title"
import TrackingSDK from "@/components/TrackingSDK"
import { getIntl } from "@/i18n"
import { setLang } from "@/i18n/serverContext"

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

import type { LangParams, PageArgs } from "@/types/params"

export { generateMetadata } from "@/utils/generateMetadata"

export default async function MyPages({
  params,
}: PageArgs<LangParams & { path: string[] }>) {
  setLang(params.lang)

  const accountPageRes = await serverClient().contentstack.accountPage.get()
  const { formatMessage } = await getIntl()

  if (!accountPageRes) {
    return null
  }

  const { tracking, accountPage } = accountPageRes

  return (
    <>
      <main className={styles.blocks}>
        <Title>{accountPage.heading}</Title>
        {accountPage.content.length ? (
          <Content content={accountPage.content} />
        ) : (
          <p>{formatMessage({ id: "No content published" })}</p>
        )}
      </main>
      <TrackingSDK pageData={tracking} />
    </>
  )
}
