import { Calendar } from "react-feather"

import { dt } from "@/lib/dt"

import Image from "@/components/Image"
import Title from "@/components/Title"

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

import type { StayCardProps } from "@/types/components/myPages/stays/stayCard"

export default function StayCard({ stay, lang }: StayCardProps) {
  const { checkinDate, checkoutDate, hotelInformation } = stay.attributes

  const arrival = dt(checkinDate).locale(lang)
  const arrivalDate = arrival.format("DD MMM")
  const arrivalDateTime = arrival.format("YYYY-MM-DD")
  const depart = dt(checkoutDate).locale(lang)
  const departDate = depart.format("DD MMM YYYY")
  const departDateTime = depart.format("YYYY-MM-DD")

  return (
    <article className={styles.stay}>
      <Image
        className={styles.image}
        alt={hotelInformation.hotelContent.images.metaData.altText}
        src={hotelInformation.hotelContent.images.imageSizes.small}
        width={420}
        height={240}
      />
      <footer className={styles.footer}>
        <Title
          as="h5"
          level="h3"
          weight="semiBold"
          uppercase
          className={styles.hotel}
        >
          {hotelInformation.hotelName}
        </Title>
        <div className={styles.date}>
          <Calendar height={20} width={20} color="var(--Main-Brand-Burgundy)" />
          <time dateTime={arrivalDateTime}>{arrivalDate}</time>
          {" - "}
          <time dateTime={departDateTime}>{departDate}</time>
        </div>
      </footer>
    </article>
  )
}
