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 { tracked } from '@glimmer/tracking';
import { guidFor } from '@ember/object/internals';
import { isBlank } from '@ember/utils';
import { keysOf } from './common.js';

var _class, _descriptor;
const insertPositions = {
  after: 'afterend',
  before: 'beforebegin'
};
const INSERT_POSITIONS = keysOf(insertPositions);
let EuiPortal = setComponentTemplate(precompileTemplate(`
    {{#if this.portalNode}}
      {{#in-element this.portalNode}}
        {{yield}}
      {{/in-element}}
    {{/if}}
  `, {
  strictMode: true
}), (_class = class EuiPortal extends Component {
  constructor(owner, args) {
    super(owner, args);
    _initializerDefineProperty(this, "portalNode", _descriptor, this);
    const {
      insert
    } = this.args;
    this.portalNode = document.createElement('div');
    this.portalNode.id = `${guidFor({})}-portal`;
    if (isBlank(this.args.insert)) {
      document.body.appendChild(this.portalNode);
    } else {
      // inserting before or after an element
      const {
        sibling,
        position
      } = insert;
      sibling.insertAdjacentElement(insertPositions[position], this.portalNode);
    }
  }
  willDestroy() {
    super.willDestroy();
    if (this.portalNode.parentNode) {
      this.portalNode.parentNode.removeChild(this.portalNode);
    }
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "portalNode", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
})), _class));

export { INSERT_POSITIONS, EuiPortal as default, insertPositions };
//# sourceMappingURL=eui-portal.js.map
