import { _ as _applyDecoratedDescriptor, b as _defineProperty } 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 { fn, hash } from '@ember/helper';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import style from 'ember-style-modifier/modifiers/style';
import { gte, and, eq } from 'ember-truth-helpers';
import { MODE_VIEWING } from '../utils/markdown/markdown-modes.js';
import EuiButtonEmpty from './eui-button-empty.js';
import EuiButtonIcon from './eui-button-icon.js';
import MarkdownCheckmark from './eui-markdown-editor-toolbar/icons/markdown-checkmark.js';
import EuiToolTip from './eui-tool-tip.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(`
    <div class="euiMarkdownEditorToolbar" ...attributes>
      <div class="euiMarkdownEditorToolbar__buttons">
        {{#each this.boldItalicsButtons as |item|}}
          <EuiToolTip @content={{item.label}} @delay="long">
            <EuiButtonIcon
              @color="text"
              {{on "click" (fn this.handleMdButtonClick item.id)}}
              @iconType={{item.iconType}}
              aria-label={{item.label}}
              @isDisabled={{this.isPreviewing}}
            />
          </EuiToolTip>

        {{/each}}
        <span class="euiMarkdownEditorToolbar__divider"></span>
        {{#each this.listButtons as |item|}}
          <EuiToolTip @content={{item.label}} @delay="long">
            <EuiButtonIcon
              @color="text"
              {{on "click" (fn this.handleMdButtonClick item.id)}}
              @iconType={{this.itemComponent item}}
              {{!@glint-expect-error}}
              @useComponent={{if item.iconType.component true}}
              aria-label={{item.label}}
              @useSvg={{item.useSvg}}
              @isDisabled={{this.isPreviewing}}
            />
          </EuiToolTip>

        {{/each}}
        <span class="euiMarkdownEditorToolbar__divider"></span>
        {{#each this.quoteCodeLinkButtons as |item|}}
          <EuiToolTip @content={{item.label}} @delay="long">
            <EuiButtonIcon
              @color="text"
              {{on "click" (fn this.handleMdButtonClick item.id)}}
              @iconType={{item.iconType}}
              aria-label={{item.label}}
              @isDisabled={{this.isPreviewing}}
            />
          </EuiToolTip>

        {{/each}}
        {{#if (gte this.uiPlugins.length 0)}}
          <span class="euiMarkdownEditorToolbar__divider"></span>
          {{#each this.uiPlugins as |plugin|}}
            {{#let
              (and @selectedNode (eq @selectedNode.type plugin.name))
              as |isSelectedNodeType|
            }}
              <EuiToolTip @content={{plugin.button.label}} @delay="long">
                <EuiButtonIcon
                  @color="text"
                  {{style
                    (if
                      isSelectedNodeType (hash background="rgba(0, 0, 0, 0.15)")
                    )
                  }}
                  {{on "click" (fn this.handleMdButtonClick plugin.name)}}
                  @iconType={{plugin.button.iconType}}
                  aria-label={{plugin.button.label}}
                  @isDisabled={{this.isPreviewing}}
                />
              </EuiToolTip>
            {{/let}}
          {{/each}}
        {{/if}}
      </div>

      {{#if this.isPreviewing}}
        <EuiButtonEmpty
          @iconType="editorCodeBlock"
          @color="text"
          @size="s"
          {{on "click" @onClickPreview}}
        >
          Editor
        </EuiButtonEmpty>

      {{else}}
        <EuiButtonEmpty
          @iconType="eye"
          @color="text"
          @size="s"
          {{on "click" @onClickPreview}}
        >
          Preview
        </EuiButtonEmpty>
      {{/if}}
    </div>
  `, {
  strictMode: true,
  scope: () => ({
    EuiToolTip,
    EuiButtonIcon,
    on,
    fn,
    gte,
    and,
    eq,
    style,
    hash,
    EuiButtonEmpty
  })
}), (_class = class EuiMarkdownEditorToolbarComponent extends Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "boldItalicsButtons", [{
      id: 'mdBold',
      label: 'Bold',
      name: 'bold',
      iconType: 'editorBold'
    }, {
      id: 'mdItalic',
      label: 'Italic',
      name: 'italic',
      iconType: 'editorItalic'
    }]);
    _defineProperty(this, "quoteCodeLinkButtons", [{
      id: 'mdQuote',
      label: 'Quote',
      name: 'quote',
      iconType: 'quote'
    }, {
      id: 'mdCode',
      label: 'Code',
      name: 'code',
      iconType: 'editorCodeBlock'
    }, {
      id: 'mdLink',
      label: 'Link',
      name: 'link',
      iconType: 'editorLink'
    }]);
  }
  get listButtons() {
    return [{
      id: 'mdUl',
      label: 'Unordered list',
      name: 'ul',
      iconType: 'editorUnorderedList'
    }, {
      id: 'mdOl',
      label: 'Ordered list',
      name: 'ol',
      iconType: 'editorOrderedList'
    }, {
      id: 'mdTl',
      label: 'Task list',
      name: 'tl',
      useSvg: true,
      iconType: {
        component: MarkdownCheckmark
      }
    }];
  }
  get uiPlugins() {
    return this.args.uiPlugins || [];
  }
  get isPreviewing() {
    return this.args.viewMode === MODE_VIEWING;
  }
  handleMdButtonClick(mdButtonId) {
    const actionResult = this.args.markdownActions.do(mdButtonId);
    if (actionResult !== true) this.args.openPluginEditor?.(actionResult);
  }
  itemComponent(item) {
    if (typeof item.iconType === 'string') return item.iconType;
    return item.iconType.component;
  }
}, (_applyDecoratedDescriptor(_class.prototype, "listButtons", [cached], Object.getOwnPropertyDescriptor(_class.prototype, "listButtons"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleMdButtonClick", [action], Object.getOwnPropertyDescriptor(_class.prototype, "handleMdButtonClick"), _class.prototype)), _class));

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