"use client"

import React, { createContext, useContext, ReactNode } from "react"

interface AppContextType {
  apiUrl: string
}

const AppContext = createContext<AppContextType | undefined>(undefined)

export function AppProvider({ children }: { children: ReactNode }) {
  const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL || ""

  return (
    <AppContext.Provider value={{ apiUrl }}>
      {children}
    </AppContext.Provider>
  )
}

export function useAppContext() {
  const context = useContext(AppContext)
  if (context === undefined) {
    throw new Error("useAppContext must be used within an AppProvider")
  }
  return context
}