"use client"

import { createContext, useContext, useState, useCallback } from "react"
import type { JobCardStatus } from "./job-card.schema"
import { JobCardShowData } from "../../../../packages/api/src/clients/job-cards"
  
 
const JobCardContext = createContext<JobCardShowData | null>(null)

export function JobCardProvider({
    jobCard,
    children,
}: {
    jobCard: JobCardShowData
    children: React.ReactNode
}) {
    const [status, setStatusState] = useState<JobCardStatus>(jobCard.status as JobCardStatus)

    const setStatus = useCallback((newStatus: JobCardStatus) => {
        setStatusState(newStatus)
    }, [])

    return (
        <JobCardContext.Provider value={{  ...jobCard, status, setStatus } as JobCardShowData}>
            {children}
        </JobCardContext.Provider>
    )
}

export function useJobCard() {
    return useContext(JobCardContext)
}
