"use client"
import { createContext, type ReactNode, useContext, useState } from "react"

import type { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"

type AlertType = AlertTypeEnum.Success | AlertTypeEnum.Alarm

const ProfilingConsentAlertContext = createContext<{
  alertType: AlertType | null
  setAlertType: (data: AlertType | null) => void
}>({
  alertType: null,
  setAlertType: () => {},
})

export function ProfilingConsentAlertProvider({
  children,
}: {
  children: ReactNode
}) {
  const [alertType, setAlertType] = useState<AlertType | null>(null)
  return (
    <ProfilingConsentAlertContext.Provider value={{ alertType, setAlertType }}>
      {children}
    </ProfilingConsentAlertContext.Provider>
  )
}

export const useProfilingConsentAlert = () =>
  useContext(ProfilingConsentAlertContext)
