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 { getValue } from '@glimmer/tracking/primitives/cache';
import Helper from '@ember/component/helper';
import { invokeHelper } from '@ember/helper';
import { throttle } from '@ember/runloop';
import { getBreakpoint } from '../utils/breakpoint.js';

var _class, _descriptor;
let CurrentBreakPointHelper = (_class = class CurrentBreakPointHelper extends Helper {
  constructor(...args) {
    super(...args);
    _initializerDefineProperty(this, "currentBreakpoint", _descriptor, this);
    _defineProperty(this, "functionToCallOnWindowResize", void 0);
  }
  compute([sizes]) {
    this.currentBreakpoint = getBreakpoint(typeof window === 'undefined' ? -Infinity : window.innerWidth);
    this.setupListeners();
    return sizes === 'all' || sizes.includes(this.currentBreakpoint);
  }
  willDestroy() {
    super.willDestroy();
    this.teardown();
  }
  setupListeners() {
    this.functionToCallOnWindowResize = () => {
      const fn = () => {
        const newBreakpoint = getBreakpoint(window.innerWidth);
        if (newBreakpoint !== this.currentBreakpoint) {
          this.currentBreakpoint = newBreakpoint;
        }
      };
      throttle(this, fn, 50);
    };
    window.addEventListener('resize', this.functionToCallOnWindowResize);
  }
  teardown() {
    if (typeof this.functionToCallOnWindowResize === 'function') {
      window.removeEventListener('resize', this.functionToCallOnWindowResize);
      this.functionToCallOnWindowResize = undefined;
    }
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "currentBreakpoint", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
})), _class);
class EuiShowForComponent extends Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "currentBreakpointHelper", invokeHelper(this, CurrentBreakPointHelper, () => {
      return {
        positional: [this.args.sizes]
      };
    }));
  }
  get shouldShow() {
    return getValue(this.currentBreakpointHelper);
  }
}
setComponentTemplate(precompileTemplate(`
    {{#if this.shouldShow}}
      {{yield}}
    {{/if}}
  `, {
  strictMode: true
}), EuiShowForComponent);

export { CurrentBreakPointHelper, EuiShowForComponent as default };
//# sourceMappingURL=eui-show-for.js.map
