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

import SectionContainer from "@/components/Section/Container"
import SectionHeader from "@/components/Section/Header"
import SectionLink from "@/components/Section/Link"

import ClientPreviousStays from "./Client"

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

export default async function PreviousStays({
  title,
  subtitle,
  link,
}: AccountPageComponentProps) {
  const caller = await serverClient()
  const initialPreviousStays = await caller.user.stays.previous({
    limit: 6,
  })

  if (!initialPreviousStays?.data.length) {
    return null
  }

  return (
    <SectionContainer>
      <SectionHeader title={title} preamble={subtitle} link={link} />
      <ClientPreviousStays initialPreviousStays={initialPreviousStays} />
      <SectionLink link={link} variant="mobile" />
    </SectionContainer>
  )
}
