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

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

import UpcomingStaysCarousel from "./Carousel"

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,
  })

  const hasStays =
    initialUpcomingStays?.data && initialUpcomingStays.data.length > 0

  if (!hasStays) return null

  return (
    <Section className={styles.container}>
      {title && <SectionHeader heading={title} link={link} />}
      <UpcomingStaysCarousel initialUpcomingStays={initialUpcomingStays} />
      <SectionLink link={link} variant="mobile" />
    </Section>
  )
}
