import { _ as _applyDecoratedDescriptor, a as _initializerDefineProperty, b as _defineProperty } from '../../_rollupPluginBabelHelpers-9wjJaosZ.js';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { get } from '@ember/object';
import { inject } from '@ember/service';
import { htmlSafe, isHTMLSafe } from '@ember/template';
import style from 'ember-style-modifier/modifiers/style';
import EuiBadge from '../eui-badge.js';
import EuiTextComponent from '../eui-text.js';

var _class, _descriptor;
function unwrap(input) {
  if (isHTMLSafe(input)) {
    return input.toString();
  }
  return input;
}
let EuiComboBoxCreateOptionComponent = setComponentTemplate(precompileTemplate(`
    <div
      class="euiComboBoxOptionsList__rowWrap"
      {{style this.extraStyling.container}}
      {{!template-lint-disable no-invalid-interactive}}
      {{on "pointerup" @onCreateOption}}
    >
      <EuiText
        class="euiComboBoxOptionsList__empty"
        @size="xs"
        {{style this.extraStyling.content}}
      >
        <div class="euiComboBoxOption__contentWrapper">
          <p class="euiComboBoxOption__emptyStateText">
            {{this.formattedString}}
          </p>

          <EuiBadge
            class="euiComboBoxOption__enterBadge"
            @color="hollow"
            @iconType={{unless @alwaysShow "returnKey"}}
          >
            {{#if @alwaysShow}}
              {{this.createLabel}}
            {{/if}}
          </EuiBadge>
        </div>
      </EuiText>
    </div>
  `, {
  strictMode: true,
  scope: () => ({
    style,
    on,
    EuiText: EuiTextComponent,
    EuiBadge
  })
}), (_class = class EuiComboBoxCreateOptionComponent extends Component {
  constructor(...args) {
    super(...args);
    _initializerDefineProperty(this, "euiI18n", _descriptor, this);
    _defineProperty(this, "_regex", /\{\s*(.*?)\s*\}/g);
  }
  get createLabel() {
    return this.euiI18n.lookupToken('euiComboBox.createLabel', 'Create');
  }
  get formattedString() {
    if (this.args.customOptionText && typeof this.args.customOptionText === 'string') {
      let str = unwrap(this.args.customOptionText);
      let context = {
        searchText: this.args.select.searchText
      };
      return htmlSafe(str.replace(this._regex, (_s, p1, p2) => {
        return get(context, p1 || p2);
      }));
    } else {
      let str = unwrap(this.euiI18n.lookupToken('euiComboBox.customOptionText', 'Add&nbsp;<strong>{searchText}</strong>&nbsp;as custom option', {
        searchText: this.args.select.searchText
      }));
      return htmlSafe(str);
    }
  }
  get extraStyling() {
    if (this.args.alwaysShow) {
      return {
        container: {
          padding: '4px 12px',
          cursor: 'pointer'
        },
        content: {
          padding: '0px'
        }
      };
    }
    return {
      container: {
        cursor: 'pointer'
      }
    };
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "euiI18n", [inject], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
})), _class));

export { EuiComboBoxCreateOptionComponent as default };
//# sourceMappingURL=create-option.js.map
