"use client" import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK" import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking" import { useSelectRateContext } from "../../../contexts/SelectRate/SelectRateContext" import useLang from "../../../hooks/useLang" import { mapPackageToLabel } from "../../../utils/getRoomFeatureDescription" import { getValidDates } from "../getValidDates" import { getSelectRateTracking } from "./tracking" import type { RouterOutput } from "@scandic-hotels/trpc/client" import type { SelectRateBooking } from "../../../types/components/selectRate/selectRate" interface TrackingProps { hotelData: NonNullable booking: SelectRateBooking } export function SelectRateTracking({ hotelData, booking }: TrackingProps) { const lang = useLang() const { input } = useSelectRateContext() const { fromDate, toDate } = getValidDates(booking.fromDate, booking.toDate) const { rooms, searchType, bookingCode } = booking const arrivalDate = fromDate.toDate() const departureDate = toDate.toDate() const specialRoomType = input.data?.booking.rooms ?.map((room) => { const packages = room.packages ?.map((pkg) => mapPackageToLabel(pkg)) .join(",") return packages ?? "" }) .join("|") const { hotelsTrackingData, pageTrackingData } = getSelectRateTracking({ lang, arrivalDate, departureDate, hotelId: hotelData.hotel.id, hotelName: hotelData.hotel.name, country: hotelData.hotel.address.country, hotelCity: hotelData.hotel.address.city, bookingCode, isRedemption: searchType === SEARCH_TYPE_REDEMPTION, specialRoomType, rooms, }) return ( ) }