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 { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

var _class, _descriptor, _descriptor2;
let EuiImage = setComponentTemplate(precompileTemplate(`
    {{yield this.setRef this.innerText}}
  `, {
  strictMode: true
}), (_class = class EuiImage extends Component {
  constructor(...args) {
    super(...args);
    _initializerDefineProperty(this, "ref", _descriptor, this);
    _initializerDefineProperty(this, "innerText", _descriptor2, this);
    _defineProperty(this, "observer", null);
  }
  get innerTextFallback() {
    return this.args.fallback ?? '';
  }
  setupObserver() {
    this.observer?.disconnect();
    this.observer = new MutationObserver(mutationsList => {
      if (mutationsList.length) this.updateInnerText(this.ref);
    });
    if (this.ref) {
      this.updateInnerText(this.ref);
      this.observer.observe(this.ref, {
        characterData: true,
        subtree: true,
        childList: true
      });
    }
  }
  updateInnerText(node) {
    if (!node) return;
    this.setInnerText(
    // Check for `innerText` implementation rather than a simple OR check
    // because in real cases the result of `innerText` could correctly be `null`
    // while the result of `textContent` could correctly be non-`null` due to
    // differing reliance on browser layout calculations.
    // We prefer the result of `innerText`, if available.
    'innerText' in node ? node.innerText : node.textContent || this.innerTextFallback);
  }
  setInnerText(text) {
    this.innerText = text;
  }
  setRef(ref) {
    this.ref = ref;
    this.setupObserver();
  }
  willDestroy() {
    super.willDestroy();
    this.observer?.disconnect();
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "ref", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return null;
  }
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "innerText", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return '';
  }
}), _applyDecoratedDescriptor(_class.prototype, "setRef", [action], Object.getOwnPropertyDescriptor(_class.prototype, "setRef"), _class.prototype)), _class));

export { EuiImage as default };
//# sourceMappingURL=eui-inner-text.js.map
