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 { action } from '@ember/object';
import { inject } from '@ember/service';
import { eq, or } from 'ember-truth-helpers';
import argOrDefault, { argOrDefaultDecorator } from '../helpers/arg-or-default.js';
import classNames from '../helpers/class-names.js';
import EuiFlexGroup from './eui-flex-group.js';
import EuiFlexItem from './eui-flex-item.js';
import EuiFormControlLayout from './eui-form-control-layout.js';
import EuiDatePopoverButton from './eui-super-date-picker/date-popover/eui-date-popover-button.js';
import EuiDatePickerRange from './eui-super-date-picker/eui-date-picker-range.js';
import EuiQuickSelectPopover from './eui-super-date-picker/eui-quick-select-popover.js';
import EuiSuperUpdateButton from './eui-super-date-picker/eui-super-update-button.js';
import { isRangeInvalid } from './eui-super-date-picker/utils/index.js';
import { useI18nTimeOptions } from './eui-super-date-picker/utils/time-options.js';

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13;
let EuiSuperDatePicker = setComponentTemplate(precompileTemplate(`
    <EuiFlexGroup
      @gutterSize="s"
      @responsive={{false}}
      class={{classNames
        "euiSuperDatePicker__flexWrapper"
        (unless
          this.showUpdateButton
          "euiSuperDatePicker__flexWrapper--noUpdateButton"
        )
        (if
          this.isAutoRefreshOnly
          "euiSuperDatePicker__flexWrapper--isAutoRefreshOnly"
        )
        (if
          @isQuickSelectOnly
          "euiSuperDatePicker__flexWrapper--isQuickSelectOnly"
        )
        (if (eq this.width "full") "euiSuperDatePicker__flexWrapper--fullWidth")
        (if (eq this.width "auto") "euiSuperDatePicker__flexWrapper--autoWidth")
      }}
    >
      <EuiFlexItem>
        <EuiFormControlLayout
          class="euiSuperDatePicker"
          @compressed={{@compressed}}
          @isDisabled={{@isDisabled}}
          @useGroup={{true}}
        >
          <:prepend>
            <EuiQuickSelectPopover
              @start={{this.start}}
              @end={{this.end}}
              @applyTime={{this.applyQuickTime}}
              @timeOptions={{this.timeOptions}}
              @isDisabled={{@isDisabled}}
              @commonlyUsedRanges={{argOrDefault
                @commonlyUsedRanges
                this.timeOptions.commonDurationRanges
              }}
            />
          </:prepend>

          <:field>
            <EuiDatePickerRange
              @className="euiDatePickerRange--inGroup"
              @isInvalid={{this.isInvalid}}
              @disabled={{@isDisabled}}
            >
              <:startDateControl>
                <EuiDatePopoverButton
                  @className="euiSuperDatePicker__startPopoverButton"
                  @value={{this.start}}
                  @compressed={{@compressed}}
                  @position="start"
                  @isDisabled={{@isDisabled}}
                  @dateFormat={{this.dateFormat}}
                  @onChange={{this.setStart}}
                  @isInvalid={{this.isInvalid}}
                  @timeOptions={{this.timeOptions}}
                  @needsUpdating={{this.hasChanged}}
                  @locale={{@locale}}
                />
              </:startDateControl>

              <:endDateControl>
                <EuiDatePopoverButton
                  @className="euiSuperDatePicker__startPopoverButton"
                  @value={{this.end}}
                  @compressed={{@compressed}}
                  @position="end"
                  @isDisabled={{@isDisabled}}
                  @dateFormat={{this.dateFormat}}
                  @onChange={{this.setEnd}}
                  @isInvalid={{this.isInvalid}}
                  @timeOptions={{this.timeOptions}}
                  @roundUp={{true}}
                  @needsUpdating={{this.hasChanged}}
                  @locale={{@locale}}
                />
              </:endDateControl>
            </EuiDatePickerRange>
          </:field>
        </EuiFormControlLayout>
      </EuiFlexItem>

      {{#if this.showUpdateButton}}
        <EuiFlexItem @grow={{false}}>
          <EuiSuperUpdateButton
            @size={{if @compressed "s" "m"}}
            @onClick={{this.handleClickUpdateButton}}
            @isLoading={{@isLoading}}
            @isDisabled={{or @isDisabled this.isInvalid}}
            @needsUpdate={{this.hasChanged}}
            @fill={{true}}
            @iconOnly={{eq this.showUpdateButton "iconOnly"}}
          />
        </EuiFlexItem>
      {{/if}}
    </EuiFlexGroup>
  `, {
  strictMode: true,
  scope: () => ({
    EuiFlexGroup,
    classNames,
    eq,
    EuiFlexItem,
    EuiFormControlLayout,
    EuiQuickSelectPopover,
    argOrDefault,
    EuiDatePickerRange,
    EuiDatePopoverButton,
    EuiSuperUpdateButton,
    or
  })
}), (_dec = argOrDefaultDecorator('MMM D, YYYY @ HH:mm:ss.SSS'), _dec2 = argOrDefaultDecorator('HH:mm'), _dec3 = argOrDefaultDecorator(false), _dec4 = argOrDefaultDecorator(false), _dec5 = argOrDefaultDecorator(true), _dec6 = argOrDefaultDecorator(true), _dec7 = argOrDefaultDecorator('restricted'), _dec8 = argOrDefaultDecorator(1000), (_class = class EuiSuperDatePicker extends Component {
  constructor(owner, args) {
    super(owner, args);
    _initializerDefineProperty(this, "dateFormat", _descriptor, this);
    _initializerDefineProperty(this, "timeFormat", _descriptor2, this);
    // @argOrDefaultDecorator('now-15m') start!: ShortDate;
    // @argOrDefaultDecorator('now') end!: ShortDate;
    _initializerDefineProperty(this, "isAutoRefreshOnly", _descriptor3, this);
    _initializerDefineProperty(this, "isDisabled", _descriptor4, this);
    _initializerDefineProperty(this, "isPaused", _descriptor5, this);
    _initializerDefineProperty(this, "showUpdateButton", _descriptor6, this);
    _initializerDefineProperty(this, "width", _descriptor7, this);
    // recentlyUsedRanges: [],
    _initializerDefineProperty(this, "refreshInterval", _descriptor8, this);
    _initializerDefineProperty(this, "euiI18n", _descriptor9, this);
    _initializerDefineProperty(this, "start", _descriptor10, this);
    _initializerDefineProperty(this, "end", _descriptor11, this);
    _initializerDefineProperty(this, "isInvalid", _descriptor12, this);
    _initializerDefineProperty(this, "hasChanged", _descriptor13, this);
    this.start = this.args.start ?? 'now-15m';
    this.end = this.args.end ?? 'now';
  }
  get timeOptions() {
    return useI18nTimeOptions(this.euiI18n);
  }
  setTime({
    start,
    end
  }) {
    this.hasChanged = !(this.start === start && this.end === end);
    this.start = start;
    this.end = end;
    this.isInvalid = isRangeInvalid(start, end);
    if (!this.showUpdateButton) {
      this.args.onTimeChange({
        start,
        end,
        isQuickSelection: false,
        isInvalid: this.isInvalid
      });
    }
  }
  applyTime() {
    this.args.onTimeChange({
      start: this.start,
      end: this.end,
      isQuickSelection: false,
      isInvalid: false
    });
  }
  applyQuickTime({
    start,
    end
  }) {
    this.start = start;
    this.end = end;
    this.args.onTimeChange({
      start,
      end,
      isQuickSelection: true,
      isInvalid: false
    });
  }
  setStart(start) {
    this.setTime({
      start,
      end: this.end
    });
  }
  setEnd(end) {
    this.setTime({
      start: this.start,
      end
    });
  }
  handleClickUpdateButton() {
    if (!this.hasChanged && this.args.onRefresh) {
      // const { start, end, refreshInterval } = this.args;
      this.args.onRefresh({
        start: this.start,
        end: this.end,
        refreshInterval: this.refreshInterval
      });
    } else {
      this.applyTime();
    }
    this.hasChanged = false;
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "dateFormat", [_dec], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "timeFormat", [_dec2], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "isAutoRefreshOnly", [_dec3], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "isDisabled", [_dec4], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "isPaused", [_dec5], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "showUpdateButton", [_dec6], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "width", [_dec7], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "refreshInterval", [_dec8], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, "euiI18n", [inject], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, "start", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, "end", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor12 = _applyDecoratedDescriptor(_class.prototype, "isInvalid", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return false;
  }
}), _descriptor13 = _applyDecoratedDescriptor(_class.prototype, "hasChanged", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return false;
  }
}), _applyDecoratedDescriptor(_class.prototype, "applyQuickTime", [action], Object.getOwnPropertyDescriptor(_class.prototype, "applyQuickTime"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "setStart", [action], Object.getOwnPropertyDescriptor(_class.prototype, "setStart"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "setEnd", [action], Object.getOwnPropertyDescriptor(_class.prototype, "setEnd"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleClickUpdateButton", [action], Object.getOwnPropertyDescriptor(_class.prototype, "handleClickUpdateButton"), _class.prototype)), _class)));

export { EuiSuperDatePicker as default };
//# sourceMappingURL=eui-super-date-picker.js.map
