'use strict';

var core = require('@shikijs/core');
var engineJavascript = require('@shikijs/engine-javascript');
var React = require('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 = React.createContext(null);
function ShikiProvider({ children, initialLanguages, initialThemes }) {
  const [highlighter, setHighlighter] = React.useState(null);
  const [isReady, setIsReady] = React.useState(false);
  const [error, setError] = React.useState(null);
  React.useEffect(() => {
    const initHighlighter = () => __async(this, null, function* () {
      try {
        const highlighterInstance = yield core.createHighlighterCore({
          engine: engineJavascript.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 = React.useMemo(
    () => ({
      highlighter,
      isReady,
      error
    }),
    [highlighter, isReady, error]
  );
  return /* @__PURE__ */ React.createElement(ShikiContext.Provider, { value }, children);
}
function useShiki() {
  const context = React.useContext(ShikiContext);
  if (!context) {
    throw new Error("useShiki must be used within a ShikiProvider");
  }
  return context;
}

exports.ShikiProvider = ShikiProvider;
exports.useShiki = useShiki;
//# sourceMappingURL=SyntaxContext.js.map
