import { b as _defineProperty } from '../_rollupPluginBabelHelpers-9wjJaosZ.js';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import Component from '@glimmer/component';
import { modifier } from 'ember-modifier';
import EuiPopoverComponent from './eui-popover.js';
import EuiPortal from './eui-portal.js';

class EuiWrappingPopover extends Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "portal", null);
    _defineProperty(this, "anchor", null);
    _defineProperty(this, "setAnchorRef", modifier(element => {
      this.anchor = element;
      this.anchor.insertAdjacentElement('beforebegin', this.args.button);
    }));
    _defineProperty(this, "setPortalRef", element => {
      this.portal = element;
    });
  }
  get insert() {
    if (this.args.button) {
      return {
        sibling: this.args.button,
        position: 'after'
      };
    }
    return;
  }
  willDestroy() {
    super.willDestroy();
    if (this.args.button && this.args.button.parentNode) {
      if (this.portal) {
        this.portal.insertAdjacentElement('beforebegin', this.args.button);
      }
    }
  }
}
setComponentTemplate(precompileTemplate(`
    <EuiPortal @portalRef={{this.setPortalRef}} @insert={{this.insert}}>
      <EuiPopover
        @closePopover={{@closePopover}}
        @isOpen={{@isOpen}}
        @anchorClassName={{@anchorClassName}}
        @anchorPosition={{@anchorPosition}}
        @attachToAnchor={{@attachToAnchor}}
        @container={{@container}}
        @display={{@display}}
        @hasArrow={{@hasArrow}}
        @initialFocus={{@initialFocus}}
        @ownFocus={{@ownFocus}}
        @panelClassName={{@panelClassName}}
        @panelPaddingSize={{@panelPaddingSize}}
        @panelStyle={{@panelStyle}}
        @panelRef={{@panelRef}}
        @popoverRef={{@popoverRef}}
        ...attributes
      >
        <:button>
          <div {{this.setAnchorRef}} class="euiWrappingPopover__anchor" />
        </:button>

        <:content>
          {{yield}}
        </:content>
      </EuiPopover>
    </EuiPortal>
  `, {
  strictMode: true,
  scope: () => ({
    EuiPortal,
    EuiPopover: EuiPopoverComponent
  })
}), EuiWrappingPopover);

export { EuiWrappingPopover as default };
//# sourceMappingURL=eui-wrapping-popover.js.map
