/* CodeRendererAdvanced.tsx generated by @compiled/babel-plugin v0.38.1 */
import "./CodeRendererAdvanced.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React, { useRef } from 'react';
import { EditorView, lineNumbers, gutters } from '@codemirror/view';
import { Compartment, EditorState } from '@codemirror/state';
import { languages } from '@codemirror/language-data';
import { syntaxHighlighting } from '@codemirror/language';
import { cmTheme, highlightStyle } from './theme';
var codeViewWrapperStyles = null;
var codeViewerHeaderBarStyles = null;
export var CodeRendererAdvanced = function CodeRendererAdvanced(props) {
  var nodeRef = 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 Compartment();
    var view = new EditorView({
      doc: props.src,
      parent: elem,
      extensions: [lineNumbers(), gutters(), EditorState.readOnly.of(true), EditorView.editable.of(false), EditorView.lineWrapping, cmTheme, syntaxHighlighting(highlightStyle), languageCompartment.of([])]
    });
    (_props$onSuccess = props.onSuccess) === null || _props$onSuccess === void 0 || _props$onSuccess.call(props);
    var language = 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.createElement("div", {
    "data-testid": props.testId,
    className: ax(["_1reo1wug _18m91wug _kqswstnw _1ltvidpf _154iidpf _1xi2idpf _94n5idpf _bfhk15j7"])
  }, /*#__PURE__*/React.createElement("div", {
    className: ax(["_4t3i8ved _bfhk1nox"])
  }), /*#__PURE__*/React.createElement("div", {
    ref: nodeRef.current
  }));
};