import { _ as _applyDecoratedDescriptor, a as _initializerDefineProperty } from '../_rollupPluginBabelHelpers-9wjJaosZ.js';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import Component from '@glimmer/component';
import { guidFor } from '@ember/object/internals';
import { inject } from '@ember/service';
import { htmlSafe } from '@ember/template';
import svgJar from 'ember-svg-jar/helpers/svg-jar';
import { and, not } from 'ember-truth-helpers';
import { argOrDefaultDecorator } from '../helpers/arg-or-default.js';
import classNames from '../helpers/class-names.js';
import { typeToPathMap, colorToClassMap } from '../utils/css-mappings/eui-icon.js';
import { keysOf } from './common.js';

var _dec, _class, _descriptor, _descriptor2;
const TYPES = keysOf(typeToPathMap);
const COLORS = keysOf(colorToClassMap);
function isNamedColor(name) {
  return Object.prototype.hasOwnProperty.call(colorToClassMap, name);
}

// We accept arbitrary color strings, which are impossible to type.

function isEuiIconType(x) {
  return typeof x === 'string' && Object.prototype.hasOwnProperty.call(typeToPathMap, x);
}
let EuiIcon = setComponentTemplate(precompileTemplate(`
    {{#if @useComponent}}
      {{!@glint-expect-error}}
      {{#let (component @type) as |IconComponent|}}
        {{!template-lint-disable}}
        <IconComponent
          class={{classNames
            @iconClasses
            this.optionalColorClass
            (if (and this.isAppIcon (not this.appIconHasColor)) "euiIcon--app")
            componentName="EuiIcon"
            size=this.size
          }}
          role="image"
          aria-hidden={{if this.isAriaHidden "true"}}
          aria-label={{if @aria-label @aria-label this.titleId}}
          aria-labelledby={{if @aria-labelledby @aria-labelledby this.titleId}}
          {{! @glint-expect-error }}
          tabindex={{@tabIndex}}
          style={{this.optionalCustomStyles}}
          color={{@color}}
          ...attributes
        />
      {{/let}}
    {{else}}
      {{#if this.useImage}}
        <img
          {{! @glint-expect-error }}
          src={{this.icon}}
          class={{classNames
            @iconClasses
            this.optionalColorClass
            (if (and this.isAppIcon (not this.appIconHasColor)) "euiIcon--app")
            componentName="EuiIcon"
            size=this.size
          }}
          color={{@color}}
          alt={{if @title @title}}
          {{! @glint-expect-error }}
          tabIndex={{@tabIndex}}
          ...attributes
        />
      {{else}}
        {{svgJar
          this.icon
          class=(classNames
            @iconClasses
            this.optionalColorClass
            (if (and this.isAppIcon (not this.appIconHasColor)) "euiIcon--app")
            componentName="EuiIcon"
            size=this.size
          )
          color=@color
          role="image"
          aria-hidden=(if this.isAriaHidden "true")
          aria-label=(if @aria-label @aria-label this.titleId)
          aria-labelledby=(if @aria-labelledby @aria-labelledby this.titleId)
          tabindex=@tabIndex
          style=this.optionalCustomStyles
        }}
      {{/if}}
    {{/if}}
  `, {
  strictMode: true,
  scope: () => ({
    classNames,
    and,
    not,
    svgJar
  })
}), (_dec = argOrDefaultDecorator('m'), (_class = class EuiIcon extends Component {
  constructor(...args) {
    super(...args);
    _initializerDefineProperty(this, "euiConfig", _descriptor, this);
    _initializerDefineProperty(this, "size", _descriptor2, this);
  }
  get useImage() {
    const {
      type
    } = this.args;
    return typeof type === 'string' && !isEuiIconType(type) && !this.useSvg;
  }
  get useSvg() {
    return this.args.useSvg ?? this.euiConfig.getConfig('euiIcon.useSvg') ?? false;
  }
  get icon() {
    const {
      type
    } = this.args;
    if (type === null) {
      return undefined;
    }

    //We should probably find a better way to always
    if (isEuiIconType(type)) {
      return this.getEuiIconSvgPath(type);
    }
    if (typeof type === 'string') {
      return type;
    }
    return undefined;
  }
  get emptyIcon() {
    return this.getEuiIconSvgPath('empty');
  }
  getEuiIconSvgPath(type) {
    return typeToPathMap[type];
  }
  get isAppIcon() {
    const {
      type
    } = this.args;
    return type && typeof type === 'string' && (/.+App$/.test(type) || /.+Job$/.test(type) || type === 'dataVisualizer');
  }
  get appIconHasColor() {
    return this.args.color && this.args.color !== 'default';
  }
  get focusable() {
    const {
      tabIndex
    } = this.args;
    return tabIndex == null || tabIndex === -1 ? 'false' : 'true';
  }
  get optionalCustomStyles() {
    const {
      color
    } = this.args;
    if (color && typeof color === 'string') {
      if (!isNamedColor(color)) {
        return htmlSafe(`fill: ${color}`);
      }
    }
    return '';
  }
  get optionalColorClass() {
    const {
      color
    } = this.args;
    if (color && typeof color === 'string') {
      if (isNamedColor(color)) {
        return colorToClassMap[color];
      } else {
        return 'euiIcon--customColor';
      }
    }
    return '';
  }

  // If it's an empty icon, or if there is no aria-label, aria-labelledby, or title it gets aria-hidden true
  get isAriaHidden() {
    const {
      icon
    } = this;
    return icon === 'empty' || !(this.args['aria-label'], this.args['aria-labelledby'], this.args.title);
  }
  get titleId() {
    const {
      title
    } = this.args;
    let titleId;

    // If no aria-label or aria-labelledby is provided but there's a title, a titleId is generated
    //  The svg aria-labelledby attribute gets this titleId
    //  The svg title element gets this titleId as an id
    if (!this.args['aria-label'] && !this.args['aria-labelledby'] && title) {
      titleId = guidFor({});
    }
    return titleId;
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "euiConfig", [inject], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "size", [_dec], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
})), _class)));

export { COLORS, TYPES, EuiIcon as default };
//# sourceMappingURL=eui-icon.js.map
