import { trackEvent } from "./base"

import type { BreakfastPackages } from "@/types/components/hotelReservation/breakfast"
import type { LowestRoomPriceEvent } from "@/types/components/tracking"

export function trackLowestRoomPrice(event: LowestRoomPriceEvent) {
  trackEvent({
    event: "lowestRoomPrice",
    hotelInfo: {
      hotelId: event.hotelId,
      arrivalDate: event.arrivalDate,
      departureDate: event.departureDate,
    },
    viewItemInfo: {
      lowestPrice: event.lowestPrice,
      currency: event.currency,
    },
  })
}

// Tracking for sections of booking flow enter-details page
export function trackBedSelection(bedType: string) {
  trackEvent({
    event: "bedSelection",
    selection: {
      name: "bed options selection click",
      bedType: bedType,
    },
    pageInfo: {
      pageName: "hotelreservation|bed",
      pageType: "bookingbedtypepage",
    },
  })
}

export function trackBreakfastSelection({
  breakfastPackage,
  hotelId,
  units,
}: {
  breakfastPackage: BreakfastPackages[number]
  hotelId: string
  units: number
}) {
  trackEvent({
    event: "breakfastSelection",
    selection: {
      name: "breakfast options selection click",
    },
    ...(units > 0 && {
      ancillaries: [
        {
          hotelId,
          productCategory: "",
          productId: breakfastPackage.code,
          productUnits: units,
          productPrice: breakfastPackage.localPrice.price * units,
          productPoints: 0,
          productType: "food",
          productName: breakfastPackage.packageType,
        },
      ],
    }),
    pageInfo: {
      pageName: "hotelreservation|breakfast",
      pageType: "bookingbreakfastpage",
    },
  })
}
