"use client"
import { PropsWithChildren, useRef } from "react"

import {
  EnterDetailsContext,
  type EnterDetailsStore,
  initEditDetailsState,
} from "@/stores/enter-details"

import { StepEnum } from "@/types/components/enterDetails/step"

export default function EnterDetailsProvider({
  step,
  children,
}: PropsWithChildren<{ step: StepEnum }>) {
  const initialStore = useRef<EnterDetailsStore>()
  if (!initialStore.current) {
    initialStore.current = initEditDetailsState(step)
  }

  return (
    <EnterDetailsContext.Provider value={initialStore.current}>
      {children}
    </EnterDetailsContext.Provider>
  )
}
