/* CodeRendererAdvanced.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CodeRendererAdvanced = void 0;
require("./CodeRendererAdvanced.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _react = _interopRequireWildcard(require("react"));
var _view = require("@codemirror/view");
var _state = require("@codemirror/state");
var _languageData = require("@codemirror/language-data");
var _language = require("@codemirror/language");
var _theme = require("./theme");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var codeViewWrapperStyles = null;
var codeViewerHeaderBarStyles = null;
var CodeRendererAdvanced = exports.CodeRendererAdvanced = function CodeRendererAdvanced(props) {
  var nodeRef = (0, _react.useRef)(function (elem) {
    var _props$item$name$spli, _props$onSuccess;
    if (!elem) {
      return;
    }
    var extension = (_props$item$name$spli = props.item.name.split('.').pop()) !== null && _props$item$name$spli !== void 0 ? _props$item$name$spli : '';
    var languageCompartment = new _state.Compartment();
    var view = new _view.EditorView({
      doc: props.src,
      parent: elem,
      extensions: [(0, _view.lineNumbers)(), (0, _view.gutters)(), _state.EditorState.readOnly.of(true), _view.EditorView.editable.of(false), _view.EditorView.lineWrapping, _theme.cmTheme, (0, _language.syntaxHighlighting)(_theme.highlightStyle), languageCompartment.of([])]
    });
    (_props$onSuccess = props.onSuccess) === null || _props$onSuccess === void 0 || _props$onSuccess.call(props);
    var language = _languageData.languages.find(function (lang) {
      return lang.extensions.includes(extension);
    });
    language === null || language === void 0 || language.load().then(function (val) {
      view.dispatch({
        effects: languageCompartment.reconfigure(val)
      });
    });
    return function () {
      view.destroy();
    };
  });
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-testid": props.testId,
    className: (0, _runtime.ax)(["_1reo1wug _18m91wug _kqswstnw _1ltvidpf _154iidpf _1xi2idpf _94n5idpf _bfhk15j7"])
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _runtime.ax)(["_4t3i8ved _bfhk1nox"])
  }), /*#__PURE__*/_react.default.createElement("div", {
    ref: nodeRef.current
  }));
};