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 { on } from '@ember/modifier';
import { action } from '@ember/object';
import { inject } from '@ember/service';
import set from 'ember-set-helper/helpers/set';
import { not, gt } from 'ember-truth-helpers';
import EuiButtonEmpty from '../eui-button-empty.js';
import EuiHorizontalRule from '../eui-horizontal-rule.js';
import EuiIcon from '../eui-icon.js';
import EuiPopoverComponent from '../eui-popover.js';
import EuiRecentlyUsed from './eui-quick-select-popover/eui-recently-used.js';
import EuiCommonlyUsedTimeRanges from './eui-quick-select-popover/eui-commonly-used-time-ranges.js';
import EuiQuickSelect from './eui-quick-select-popover/eui-quick-select.js';
import { useI18nTimeOptions } from './utils/time-options.js';

var _class, _descriptor, _descriptor2;
let EuiQuickSelectPopover = setComponentTemplate(precompileTemplate(`
    <EuiPopover
      @isOpen={{this.isOpen}}
      @closePopover={{set this "isOpen" false}}
      @anchorPosition="downLeft"
      @anchorClassName="euiQuickSelectPopover__anchor"
    >
      <:button>
        <EuiButtonEmpty
          class="euiFormControlLayout__prepend"
          @textClasses="euiQuickSelectPopover__buttonText"
          @size="xs"
          @iconType="arrowDown"
          @iconSide="right"
          @isDisabled={{@isDisabled}}
          {{on "click" (set this "isOpen" (not this.isOpen))}}
        >
          <EuiIcon @type="calendar" />
        </EuiButtonEmpty>
      </:button>

      <:content>
        <div class="euiQuickSelectPopover__content">
          <EuiQuickSelect
            @applyTime={{this.applyTime}}
            @start={{@start}}
            @end={{@end}}
            @timeOptions={{this.timeOptions}}
          />

          {{#if (gt @commonlyUsedRanges.length 0)}}
            <EuiHorizontalRule @margin="s" />
            <EuiCommonlyUsedTimeRanges
              @applyTime={{this.applyTime}}
              @commonlyUsedRanges={{@commonlyUsedRanges}}
            />
          {{/if}}

          {{#if (gt @recentlyUsedRanges.length 0)}}
            <EuiHorizontalRule @margin="s" />
            <EuiRecentlyUsed
              @applyTime={{this.applyTime}}
              @recentlyUsedRanges={{@recentlyUsedRanges}}
            />
          {{/if}}

        </div>
      </:content>
    </EuiPopover>
  `, {
  strictMode: true,
  scope: () => ({
    EuiPopover: EuiPopoverComponent,
    set,
    EuiButtonEmpty,
    on,
    not,
    EuiIcon,
    EuiQuickSelect,
    gt,
    EuiHorizontalRule,
    EuiCommonlyUsedTimeRanges,
    EuiRecentlyUsed
  })
}), (_class = class EuiQuickSelectPopover extends Component {
  constructor(...args) {
    super(...args);
    _initializerDefineProperty(this, "euiI18n", _descriptor, this);
    _initializerDefineProperty(this, "isOpen", _descriptor2, this);
  }
  applyTime({
    start,
    end,
    keepPopoverOpen = false
  }) {
    this.args.applyTime({
      start,
      end
    });
    if (!keepPopoverOpen) {
      this.isOpen = false;
    }
  }
  get timeOptions() {
    return this.args.timeOptions || useI18nTimeOptions(this.euiI18n);
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "euiI18n", [inject], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "isOpen", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return false;
  }
}), _applyDecoratedDescriptor(_class.prototype, "applyTime", [action], Object.getOwnPropertyDescriptor(_class.prototype, "applyTime"), _class.prototype)), _class));

export { EuiQuickSelectPopover as default };
//# sourceMappingURL=eui-quick-select-popover.js.map
