"use client"

import { BookingFlowContextProvider } from "@scandic-hotels/booking-flow/BookingFlowContextProvider"
import { BookingFlowTrackingProvider } from "@scandic-hotels/booking-flow/BookingFlowTrackingProvider"
import { trackEvent } from "@scandic-hotels/common/tracking/base"

import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
import { trackAccordionClick, trackOpenSidePeekEvent } from "@/utils/tracking"
import { trackBookingSearchClick } from "@/utils/tracking/booking"

import type { ReactNode } from "react"

export function BookingFlowProviders({ children }: { children: ReactNode }) {
  const isLoggedIn = useIsUserLoggedIn()

  return (
    <BookingFlowContextProvider data={{ isLoggedIn }}>
      <BookingFlowTrackingProvider
        trackingFunctions={{
          trackBookingSearchClick,
          trackAccordionItemOpen: trackAccordionClick,
          trackOpenSidePeek: trackOpenSidePeekEvent,
          trackGenericEvent: trackEvent,
        }}
      >
        {children}
      </BookingFlowTrackingProvider>
    </BookingFlowContextProvider>
  )
}
