"use client"
import { notFound, useSearchParams } from "next/navigation"
import { useIntl } from "react-intl"
import { trpc } from "@scandic-hotels/trpc/client"
import { selectRateRoomsAvailabilityInputSchema } from "@scandic-hotels/trpc/routers/hotels/input"
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
import Alert from "@/components/TempDesignSystem/Alert"
import useLang from "@/hooks/useLang"
import RatesProvider from "@/providers/RatesProvider"
import { parseSelectRateSearchParams, searchParamsToRecord } from "@/utils/url"
import RateSummary from "./RateSummary"
import Rooms from "./Rooms"
import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
import styles from "./index.module.css"
import type { RoomsContainerProps } from "@/types/components/hotelReservation/selectRate/roomsContainer"
export function RoomsContainer({
hotelType,
roomCategories,
vat,
}: RoomsContainerProps) {
const lang = useLang()
const intl = useIntl()
const searchParams = useSearchParams()
const booking = parseSelectRateSearchParams(
searchParamsToRecord(searchParams)
)
if (!booking) return notFound()
const bookingInput = selectRateRoomsAvailabilityInputSchema.safeParse({
booking,
lang,
})
const { data, isFetching, isError, error } =
trpc.hotel.availability.selectRate.rooms.useQuery(bookingInput.data!, {
retry(failureCount, error) {
if (error.data?.code === "BAD_REQUEST") {
return false
}
return failureCount <= 3
},
enabled: bookingInput.success,
})
if (isFetching) {
return