import { createHighlighterCore } from '@shikijs/core';
import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript';
import React, { createContext, useState, useEffect, useMemo, useContext } from 'react';

var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
const ShikiContext = createContext(null);
function ShikiProvider({ children, initialLanguages, initialThemes }) {
  const [highlighter, setHighlighter] = useState(null);
  const [isReady, setIsReady] = useState(false);
  const [error, setError] = useState(null);
  useEffect(() => {
    const initHighlighter = () => __async(this, null, function* () {
      try {
        const highlighterInstance = yield createHighlighterCore({
          engine: createJavaScriptRegexEngine()
        });
        setHighlighter(highlighterInstance);
        setIsReady(true);
        setError(null);
        console.log("Initial languages:", initialLanguages);
        console.log("Initial themes:", initialThemes);
        console.log("Initial theme 1:", initialThemes[0]);
      } catch (err) {
        console.error("Highlighter initialization failed:", err);
        setError(err instanceof Error ? err : new Error("Initialization failed"));
        setIsReady(false);
      }
    });
    initHighlighter();
  }, [initialLanguages, initialThemes]);
  const value = useMemo(
    () => ({
      highlighter,
      isReady,
      error
    }),
    [highlighter, isReady, error]
  );
  return /* @__PURE__ */ React.createElement(ShikiContext.Provider, { value }, children);
}
function useShiki() {
  const context = useContext(ShikiContext);
  if (!context) {
    throw new Error("useShiki must be used within a ShikiProvider");
  }
  return context;
}

export { ShikiProvider, useShiki };
//# sourceMappingURL=SyntaxContext.js.map
