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

import DigitalTeamMemberCard from "@/components/MyPages/DigitalTeamMemberCard"
import SectionContainer from "@/components/Section/Container"
import SectionHeader from "@/components/Section/Header"
import SectionLink from "@/components/Section/Link"
import Divider from "@/components/TempDesignSystem/Divider"

import Hero from "./Friend/Hero"
import MembershipNumber from "./Friend/MembershipNumber"
import Friend from "./Friend"
import Stats from "./Stats"

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

import type { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"

export default async function Overview({
  link,
  subtitle,
  title,
}: AccountPageComponentProps) {
  const user = await getProfile()
  if (!user || "error" in user) {
    return null
  }

  return (
    <SectionContainer>
      <SectionHeader
        link={link}
        preamble={subtitle}
        title={title}
        headingAs="h3"
        headingLevel="h1"
      />
      <DigitalTeamMemberCard user={user} />
      <Hero color="red">
        <Friend membership={user.membership} name={user.name}>
          <MembershipNumber color="burgundy" membership={user.membership} />
        </Friend>
        <Divider className={styles.divider} color="peach" />
        <Stats user={user} />
      </Hero>
      <SectionLink link={link} variant="mobile" />
    </SectionContainer>
  )
}
