"use client"

import { ApiResponse } from "@garage/api"
import { createContext, useContext } from "react"
type InvoiceContextValue = {
    id: number | string
    subject?: string | null
    invoice_number?: string | null
    discount?: string | null
    sub_total?: number | string | null
    total?: number | string | null
    payments_recieved?: number | string | null
    received_payment?: number | string | null
    balance_due?: number | string | null
    amount?: number | string | null
    invoice_parts?: { quantity?: string | number; rate?: string | number }[]
    invoice_services?: { quantity?: string | number; rate?: string | number }[]
    invoice_expenses?: { quantity?: string | number; rate?: string | number }[]
    [key: string]: unknown
}

const InvoiceContext = createContext<InvoiceContextValue | null>(null)

export function InvoiceProvider({
    invoice,
    children,
}: {
    invoice: InvoiceContextValue
    children: React.ReactNode
}) {
    return (
        <InvoiceContext.Provider value={invoice}>
            {children}
        </InvoiceContext.Provider>
    )
}

export function useInvoice() {
    return useContext(InvoiceContext)
}
