var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.useSyntaxHighlighter = useSyntaxHighlighter;var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _syntax = require("../syntax");

function useSyntaxHighlighter(_ref) {var text = _ref.text,lang = _ref.lang,langName = _ref.langName,theme = _ref.theme,themeName = _ref.themeName;
  var _useState = (0, _react.useState)([]),_useState2 = (0, _slicedToArray2.default)(_useState, 2),tokens = _useState2[0],setTokens = _useState2[1];
  var _useState3 = (0, _react.useState)(),_useState4 = (0, _slicedToArray2.default)(_useState3, 2),error = _useState4[0],setError = _useState4[1];
  var _useState5 = (0, _react.useState)(true),_useState6 = (0, _slicedToArray2.default)(_useState5, 2),isLoading = _useState6[0],setIsLoading = _useState6[1];

  (0, _react.useEffect)(function () {
    var mounted = true;
    setIsLoading(true);function

    highlight() {return _highlight.apply(this, arguments);}function _highlight() {_highlight = (0, _asyncToGenerator2.default)(function* () {
        if (!text) {
          setIsLoading(false);
          setTokens([]);
          return;
        }

        try {
          var highlighter = yield (0, _syntax.createHighlighter)({
            langs: [lang],
            themes: [theme]
          });

          var result = highlighter.codeToTokens(text, {
            lang: langName,
            theme: themeName
          });

          if (mounted && result.tokens) {
            setTokens(result.tokens);
            setError(undefined);
          }
        }
        catch (err) {
          console.error('Highlighting error:', err);
          if (mounted) {
            setError(err instanceof Error ? err.message : 'Syntax highlighting failed');
            setTokens([]);
          }
        } finally
        {
          if (mounted) {
            setIsLoading(false);
          }
        }
      });return _highlight.apply(this, arguments);}

    highlight();
    return function () {
      mounted = false;
    };
  }, [text, lang, langName, theme, themeName]);

  return { tokens: tokens, error: error, isLoading: isLoading };
}
//# sourceMappingURL=useSyntaxHighlighter.js.map