"use client"

import { createContext, useContext } from "react"

export type TrackingFunctions = {
  trackBookingSearchClick: (
    searchTerm: string,
    searchType: "hotel" | "destination"
  ) => void
  trackAccordionItemOpen: (option: string) => void
}

export const TrackingContext = createContext<TrackingFunctions | undefined>(
  undefined
)

export const useTrackingContext = (): TrackingFunctions => {
  const context = useContext(TrackingContext)

  if (!context) {
    throw new Error(
      "useTrackingContext must be used within a BookingFlowTrackingProvider. Did you forget to use the provider in the consuming app?"
    )
  }

  return context
}
