import { createContext, useContext } from 'react'
import type { ReactNode } from 'react'

interface ProductContextType {
  productName: string
}

const ProductContext = createContext<ProductContextType | undefined>(undefined)

interface ProductProviderProps {
  children: ReactNode
  productName: string
}

export function ProductProvider({ children, productName }: ProductProviderProps) {
  return <ProductContext.Provider value={{ productName }}>{children}</ProductContext.Provider>
}

export function useProduct() {
  const context = useContext(ProductContext)
  if (!context) {
    throw new Error('useProduct must be used within a ProductProvider')
  }
  return context
}
