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 { concat, hash } from '@ember/helper';
import { on } from '@ember/modifier';
import { inject } from '@ember/service';
import set from 'ember-set-helper/helpers/set';
import { not } from 'ember-truth-helpers';
import classNames from '../../../helpers/class-names.js';
import EuiPopoverComponent from '../../eui-popover.js';
import { useFormatTimeString } from '../utils/index.js';
import { useI18nTimeOptions } from '../utils/time-options.js';
import EuiDatePopoverContent from './eui-date-popover-content.js';

var _class, _descriptor, _descriptor2;
let EuiDatePopoverButton = setComponentTemplate(precompileTemplate(`
    {{#let
      (classNames
        "euiDatePopoverButton"
        (concat "euiDatePopoverButton--" @position)
        (if @compressed "euiDatePopoverButton--compressed")
        (if this.isOpen "euiDatePopoverButton-isSelected")
        (if @isInvalid "euiDatePopoverButton-isInvalid")
        (if @needsUpdating "euiDatePopoverButton-needsUpdating")
        (if @isDisabled "euiDatePopoverButton-disabled")
      )
      as |classes|
    }}
      <EuiPopover
        @isOpen={{this.isOpen}}
        @closePopover={{set this "isOpen" false}}
        @anchorPosition={{this.anchorPosition}}
        @panelPaddingSize="none"
        @display="block"
      >
        <:button>
          {{#if (has-block "button")}}
            {{yield
              (hash
                classes=classes
                formattedValue=this.formattedValue
                open=(set this "isOpen" true)
                close=(set this "isOpen" false)
              )
              to="button"
            }}
          {{else}}
            <button
              type="button"
              class={{classes}}
              title={{this.formattedValue}}
              disabled={{@isDisabled}}
              ...attributes
              {{on "click" (set this "isOpen" (not this.isOpen))}}
            >
              {{this.formattedValue}}
            </button>
          {{/if}}
        </:button>

        <:content>
          <EuiDatePopoverContent
            @position={{this.position}}
            @value={{@value}}
            @roundUp={{@roundUp}}
            @dateFormat={{this.dateFormat}}
            @timeFormat={{@timeFormat}}
            @locale={{@locale}}
            @utcOffset={{@utcOffset}}
            @timeOptions={{this.timeOptions}}
            @onChange={{@onChange}}
          />
        </:content>
      </EuiPopover>
    {{/let}}
  `, {
  strictMode: true,
  scope: () => ({
    classNames,
    concat,
    EuiPopover: EuiPopoverComponent,
    set,
    hash,
    on,
    not,
    EuiDatePopoverContent
  })
}), (_class = class EuiDatePopoverButton extends Component {
  constructor(...args) {
    super(...args);
    _initializerDefineProperty(this, "euiI18n", _descriptor, this);
    _initializerDefineProperty(this, "isOpen", _descriptor2, this);
  }
  get dateFormat() {
    //date with seconds and such
    return this.args.dateFormat ?? 'YYYY-MM-DDTHH:mm:ss.SSSZ';
  }
  get formattedValue() {
    const roundUp = this.args.roundUp ?? false;
    const locale = this.args.locale ?? 'en';
    return useFormatTimeString(this.args.value, this.dateFormat, roundUp, locale, this.euiI18n);
  }
  get timeOptions() {
    return this.args.timeOptions || useI18nTimeOptions(this.euiI18n);
  }
  get anchorPosition() {
    return this.args.position === 'start' ? 'downLeft' : 'downRight';
  }
  get position() {
    return this.args.position ?? 'start';
  }
}, (_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;
  }
})), _class));

export { EuiDatePopoverButton as default };
//# sourceMappingURL=eui-date-popover-button.js.map
