"use client"

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

import { useIsUserLoggedIn } from "../hooks/useIsUserLoggedIn"
import {
  trackAccordionItemOpen,
  trackBedSelection,
  trackBookingSearchClick,
  trackBreakfastSelection,
  trackGenericEvent,
  trackGlaSaveCardAttempt,
  trackLoginClick,
  trackOpenSidePeek,
  trackPaymentEvent,
  trackUpdatePaymentMethod,
} from "../utils/tracking"

import type { ReactNode } from "react"

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

  return (
    <BookingFlowContextProvider data={{ isLoggedIn }}>
      <BookingFlowTrackingProvider
        trackingFunctions={{
          trackBookingSearchClick,
          trackAccordionItemOpen,
          trackOpenSidePeek,
          trackGenericEvent,
          trackGlaSaveCardAttempt,
          trackLoginClick,
          trackPaymentEvent,
          trackUpdatePaymentMethod,
          trackBreakfastSelection,
          trackBedSelection,
        }}
      >
        {children}
      </BookingFlowTrackingProvider>
    </BookingFlowContextProvider>
  )
}
