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

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

import ClientUpcomingStays from "./Client"
import EmptyUpcomingStaysBlock from "./EmptyUpcomingStays"

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

export default async function UpcomingStays({
  lang,
  title,
  subtitle,
  link,
}: AccountPageComponentProps) {
  const initialUpcomingStays = await serverClient().user.stays.upcoming()
  if (!initialUpcomingStays?.data) {
    return null
  }
  return (
    <SectionContainer>
      <SectionHeader title={title} subtitle={subtitle} link={link} />
      {initialUpcomingStays.data.length ? (
        <ClientUpcomingStays
          initialUpcomingStays={initialUpcomingStays}
          lang={lang}
        />
      ) : (
        <EmptyUpcomingStaysBlock lang={lang} />
      )}
    </SectionContainer>
  )
}
