import React, { createContext, useContext } from 'react';
import { GoonClient } from './api';

const Ctx = createContext<GoonClient | null>(null);

export function ClientProvider({ client, children }: { client: GoonClient; children: React.ReactNode }) {
  return <Ctx.Provider value={client}>{children}</Ctx.Provider>;
}

export function useClient(): GoonClient {
  const c = useContext(Ctx);
  if (!c) throw new Error('useClient outside ClientProvider');
  return c;
}
