"use client"

import { createContext } from "react"

type BaseUser = {
  firstName: string | null
  lastName: string | null
  email: string
}

export type BookingFlowUser =
  | (BaseUser & {
      type: "partner"
      partnerLoyaltyNumber: string
      isLinked: boolean
    })
  | (BaseUser & {
      type: "scandic"
      /**
       * This will always be null for Scandic Friends members
       */
      partnerLoyaltyNumber: null
      membershipNumber: string
    })

export type BookingFlowContextData = {
  isLoggedIn: boolean
  user:
    | { state: "loading"; data: undefined }
    | { state: "error"; data: undefined }
    | { state: "loaded"; data: BookingFlowUser | undefined }
}

export const BookingFlowContext = createContext<
  BookingFlowContextData | undefined
>(undefined)
