"use client"

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

import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
import {
  trackAccordionClick,
  trackLoginClick,
  trackOpenSidePeekEvent,
  trackPaymentEvent,
  trackUpdatePaymentMethod,
} from "@/utils/tracking"
import {
  trackBedSelection,
  trackBookingSearchClick,
  trackBreakfastSelection,
} from "@/utils/tracking/booking"
import { trackGlaSaveCardAttempt } from "@/utils/tracking/myStay"

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,
          trackGlaSaveCardAttempt,
          trackLoginClick,
          trackPaymentEvent,
          trackUpdatePaymentMethod,
          trackBreakfastSelection,
          trackBedSelection,
        }}
      >
        {children}
      </BookingFlowTrackingProvider>
    </BookingFlowContextProvider>
  )
}
