import { notFound } from "next/navigation"

import { env } from "@/env/server"
import { getHotel, getHotelPage } from "@/lib/trpc/memoizedRequests"

import { getLang } from "@/i18n/serverContext"

import HotelMapPageClient from "./Client"

interface HotelMapPageProps {
  hotelId: string
}

export default async function HotelMapPage({ hotelId }: HotelMapPageProps) {
  const lang = await getLang()
  const hotelPageData = await getHotelPage()
  const hotelData = await getHotel({
    hotelId,
    isCardOnlyPayment: false,
    language: lang,
  })

  if (!hotelPageData || !hotelData) {
    notFound()
  }

  const { name, location, pointsOfInterest, hotelType } = hotelData.hotel

  const coordinates = {
    lat: location.latitude,
    lng: location.longitude,
  }
  return (
    <HotelMapPageClient
      apiKey={env.GOOGLE_STATIC_MAP_KEY}
      mapId={env.GOOGLE_DYNAMIC_MAP_ID}
      hotelName={name}
      markerInfo={{ hotelId, hotelType }}
      coordinates={coordinates}
      pointsOfInterest={pointsOfInterest}
    />
  )
}
