import { _ as _applyDecoratedDescriptor } from '../_rollupPluginBabelHelpers-9wjJaosZ.js';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
import Component from '@glimmer/component';
import '@glimmer/tracking';
import { isArray } from '@ember/array';
import { EnsureSafeComponentHelper } from '@embroider/util';
import optional from 'ember-composable-helpers/helpers/optional';
import unified from 'unified';
import { sizeMapping } from '../utils/css-mappings/eui-text.js';
import { defaultParsingPlugins } from '../utils/markdown/plugins/markdown-default-plugins/parsing-plugins.js';
import { defaultProcessingPlugins } from '../utils/markdown/plugins/markdown-default-plugins/processing-plugins.js';
import '../utils/markdown/plugins/markdown-default-plugins/ui-plugins.js';
import { toDOM } from '../utils/markdown/plugins/to-dom.js';

var _class;
let cached = macroCondition(dependencySatisfies('ember-source', '>= 4.1.0-alpha.0')) ? importSync('@glimmer/tracking').cached : importSync('ember-cached-decorator-polyfill').cached;
let EuiMarkdownEditorToolbarComponent = setComponentTemplate(precompileTemplate(`
    {{! This hbs was inspired by https://github.com/ampatspell/ember-cli-remark-static/blob/v3.0.5/addon/components/remark.hbs }}
    {{#if this.result}}
      {{this.result.element}}
      {{#each this.result.components as |CompNode|}}
        {{#in-element CompNode.element}}
          {{#if CompNode.componentName}}
            {{#let
              (component (EnsureSafeComponentHelper CompNode.componentName))
              as |DynamicComponent|
            }}
              <DynamicComponent
                @replaceNode={{optional @replaceNode}}
                @node={{CompNode}}
              />
            {{/let}}
          {{/if}}
        {{/in-element}}
      {{/each}}
    {{/if}}
  `, {
  strictMode: true,
  scope: () => ({
    EnsureSafeComponentHelper,
    optional
  })
}), (_class = class EuiMarkdownEditorToolbarComponent extends Component {
  get parsingPluginList() {
    return this.args.parsingPluginList || defaultParsingPlugins;
  }
  get processingPluginList() {
    return this.args.processingPluginList || defaultProcessingPlugins;
  }
  get processor() {
    const Compiler = tree => {
      return tree;
    };
    function identityCompiler() {
      //eslint-disable-next-line
      this.Compiler = Compiler;
    }
    return unified().use(this.parsingPluginList).use(this.processingPluginList).use(identityCompiler);
  }
  get shouldIncludeDefaultRootClasses() {
    return this.args.shouldIncludeDefaultRootClasses ?? true;
  }
  get rootClasses() {
    let baseClasses = ['euiMarkdownFormat'];
    if (this.shouldIncludeDefaultRootClasses) {
      baseClasses = baseClasses.concat(['euiText', this.textSizeClass]);
    }
    if (this.args.rootClasses) {
      let rootClasses = isArray(this.args.rootClasses) ? this.args.rootClasses : this.args.rootClasses?.trim()?.split(' ') || [];
      baseClasses = baseClasses.concat(rootClasses);
    }
    return baseClasses;
  }
  get textSize() {
    return this.args.textSize || 'm';
  }
  get textSizeClass() {
    return sizeMapping[this.textSize];
  }
  get result() {
    try {
      const processed = this.processor.processSync(this.args.value);
      return toDOM(processed['result'], {
        rootClasses: this.rootClasses
      });
      //eslint-disable-next-line
    } catch (e) {
      console.warn(e);
    }
    return null;
  }
}, (_applyDecoratedDescriptor(_class.prototype, "processor", [cached], Object.getOwnPropertyDescriptor(_class.prototype, "processor"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "result", [cached], Object.getOwnPropertyDescriptor(_class.prototype, "result"), _class.prototype)), _class));

export { EuiMarkdownEditorToolbarComponent as default };
//# sourceMappingURL=eui-markdown-format.js.map
