"use client"

import { createContext, useContext } from "react"

export type PurchaseOrderContextValue = {
    id: string
    label: string
    data?: Record<string, any>
}

const PurchaseOrderContext = createContext<PurchaseOrderContextValue | null>(null)

export function PurchaseOrderProvider({
    purchaseOrder,
    children,
}: {
    purchaseOrder: PurchaseOrderContextValue
    children: React.ReactNode
}) {
    return (
        <PurchaseOrderContext.Provider value={purchaseOrder}>
            {children}
        </PurchaseOrderContext.Provider>
    )
}

export function usePurchaseOrder() {
    return useContext(PurchaseOrderContext)
}
