'use client';

// src/contexts/EventBusContext.tsx
import { createContext, useContext, useRef } from "react";
import { EventBus } from "@semiont/core";
import { jsx } from "react/jsx-runtime";
var EventBusContext = createContext(null);
function EventBusProvider({ children }) {
  const eventBusRef = useRef(null);
  if (!eventBusRef.current) {
    eventBusRef.current = new EventBus();
  }
  const eventBus = eventBusRef.current;
  return /* @__PURE__ */ jsx(EventBusContext.Provider, { value: eventBus, children });
}
function useEventBus() {
  const eventBus = useContext(EventBusContext);
  if (!eventBus) {
    throw new Error("useEventBus must be used within EventBusProvider");
  }
  return eventBus;
}

// src/contexts/ApiClientContext.tsx
import { createContext as createContext2, useContext as useContext2, useMemo } from "react";
import { baseUrl } from "@semiont/core";
import { SemiontApiClient } from "@semiont/api-client";
import { jsx as jsx2 } from "react/jsx-runtime";
var ApiClientContext = createContext2(void 0);
function ApiClientProvider({
  baseUrl: url,
  children
}) {
  const eventBus = useEventBus();
  const client = useMemo(
    () => new SemiontApiClient({
      baseUrl: baseUrl(url),
      eventBus,
      // Use no timeout in test environment to avoid AbortController issues with ky + vitest
      ...process.env.NODE_ENV !== "test" && { timeout: 3e4 }
    }),
    [url, eventBus]
  );
  return /* @__PURE__ */ jsx2(ApiClientContext.Provider, { value: client, children });
}
function useApiClient() {
  const context = useContext2(ApiClientContext);
  if (context === void 0) {
    throw new Error("useApiClient must be used within an ApiClientProvider");
  }
  return context;
}

export {
  EventBusProvider,
  useEventBus,
  ApiClientProvider,
  useApiClient
};
//# sourceMappingURL=chunk-HNZOXH4L.mjs.map