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

import { Section } from "@/components/Section"
import SectionHeader from "@/components/Section/Header/Deprecated"
import SectionLink from "@/components/Section/Link"

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

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

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

export default async function UpcomingStays({
  title,
  link,
}: AccountPageComponentProps) {
  const caller = await serverClient()
  const initialUpcomingStays = await caller.user.stays.upcoming({
    limit: 6,
  })

  return (
    <Section className={styles.container}>
      <SectionHeader title={title} link={link} />
      {initialUpcomingStays?.data.length ? (
        <ClientUpcomingStays initialUpcomingStays={initialUpcomingStays} />
      ) : (
        <EmptyUpcomingStaysBlock />
      )}
      <SectionLink link={link} variant="mobile" />
    </Section>
  )
}
