import { redirect } from "next/navigation"

import { myPages, overview } from "@/constants/routes/myPages"
import { serverClient } from "@/lib/trpc/server"

import MaxWidth from "@/components/MaxWidth"
import Content from "@/components/MyPages/AccountPage/Content"

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

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

export default async function MyPages({
  params,
  searchParams,
}: PageArgs<LangParams, UriParams>) {
  if (!searchParams.uri) {
    throw new Error("Bad URI")
  }

  const accountPage = await serverClient().contentstack.accountPage.get({
    url: searchParams.uri,
    lang: params.lang,
  })

  return (
    <MaxWidth className={styles.blocks} tag="main">
      <Content lang={params.lang} content={accountPage.content} />
    </MaxWidth>
  )
}
