'use client';

import { createContext, useContext } from 'react';
import type { CrmApi } from './types';

const CrmApiContext = createContext<CrmApi | null>(null);

export const CrmApiProvider = CrmApiContext.Provider;

export function useCrmApi(): CrmApi {
  const api = useContext(CrmApiContext);
  if (!api) throw new Error('useCrmApi must be used within <CrmApiProvider>');
  return api;
}
