import { brandWorkOsOrgId } from './chunk-MQZE7SUI.js';
import { createContext, useContext, useMemo } from 'react';
import { jsx } from 'react/jsx-runtime';

var ElevasisServiceContext = createContext(null);
function useElevasisServices() {
  const ctx = useContext(ElevasisServiceContext);
  if (!ctx) {
    throw new Error(
      "useElevasisServices must be used within an ElevasisServiceProvider or an ElevasisUIProvider with apiUrl configured."
    );
  }
  return ctx;
}
function ElevasisServiceProvider({
  apiRequest,
  organizationId,
  workOSOrganizationId,
  isReady,
  children
}) {
  const resolvedOrganizationId = brandWorkOsOrgId(workOSOrganizationId ?? organizationId ?? null);
  const value = useMemo(
    () => ({
      apiRequest,
      organizationId: resolvedOrganizationId,
      workOSOrganizationId: resolvedOrganizationId,
      isReady
    }),
    [apiRequest, resolvedOrganizationId, isReady]
  );
  return /* @__PURE__ */ jsx(ElevasisServiceContext.Provider, { value, children });
}

export { ElevasisServiceContext, ElevasisServiceProvider, useElevasisServices };
