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 { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import { later } from '@ember/runloop';
import optional from 'ember-composable-helpers/helpers/optional';
import { and, not, eq } from 'ember-truth-helpers';
import argOrDefault, { argOrDefaultDecorator } from '../helpers/arg-or-default.js';
import castTo from '../helpers/cast-to.js';
import classNames from '../helpers/class-names.js';
import { isWithinRange } from '../utils/number/number.js';
import EuiInputPopoverComponent from './eui-input-popover.js';
import EuiRangeHighlight from './eui-range-highlight.js';
import EuiRangeInput from './eui-range-input.js';
import EuiRangeLabel from './eui-range-label.js';
import EuiRangeSlider from './eui-range-slider.js';
import EuiRangeToolipComponent from './eui-range-tooltip.js';
import EuiRangeTrackComponent from './eui-range-track.js';
import EuiRangeWrapper from './eui-range-wrapper.js';

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14;
let EuiRangeComponent = setComponentTemplate(precompileTemplate(`
    {{#let
      (and (argOrDefault @isPrependProvided true) (has-block "prepend"))
      (and (argOrDefault @isAppendProvided true) (has-block "append"))
      (and (not (argOrDefault @isFakeMaxBlock false)) (has-block "max"))
      (and (not (argOrDefault @isFakeMinBlock false)) (has-block "min"))
      (and (not (argOrDefault @isFakeValueBlock false)) (has-block "value"))
      (and
        (not (argOrDefault @isFakeValueAppendBlock false))
        (has-block "valueAppend")
      )
      (and
        (not (argOrDefault @isFakeValuePrependBlock false))
        (has-block "valuePrepend")
      )
      as |hasPrepend hasAppend hasMaxBlock hasMinBlock hasValueBlock hasValueAppendBlock hasValuePrependBlock|
    }}
      {{#if this.showInputOnly}}
        <EuiInputPopover
          class="euiRange__popover"
          @fullWidth={{@fullWidth}}
          @isOpen={{this.isPopoverOpen}}
          @closePopover={{this.closePopover}}
          @disableFocusTrap={{true}}
        >
          <:input>
            <EuiRangeInput
              id={{this.id}}
              @min={{this.min}}
              @max={{this.max}}
              @digitTolerance={{this.digitTolerance}}
              @readOnly={{@readOnly}}
              @step={{this.step}}
              @value={{@value}}
              @disabled={{@disabled}}
              @compressed={{@compressed}}
              @name={{@name}}
              @fullWidth={{and this.showInputOnly this.fullWidth}}
              @isLoading={{and this.showInputOnly @isLoading}}
              @isInvalid={{@isInvalid}}
              @autoSize={{not this.showInputOnly}}
              @isPrependProvided={{hasPrepend}}
              @isAppendProvided={{hasAppend}}
              ...attributes
              {{on
                "focus"
                (if this.canShowDropdown this.onInputFocus (optional @onFocus))
              }}
              {{on
                "blur"
                (if this.canShowDropdown this.onInputBlur (optional @onBlur))
              }}
              {{on "input" this.handleOnChange}}
            >
              <:prepend as |classes|>
                {{yield classes to="prepend"}}
              </:prepend>
              <:append as |classes|>
                {{yield classes to="append"}}
              </:append>
            </EuiRangeInput>
          </:input>
          <:content>
            <EuiRangeWrapper
              class={{classNames
                "euiRange"
                (if this.showInput "euiRange--hasInput")
              }}
              @fullWidth={{@fullWidth}}
              @compressed={{@compressed}}
            >
              {{#if this.showLabels}}
                <EuiRangeLabel @side="min" @disabled={{@disabled}}>
                  {{#if hasMinBlock}}
                    {{yield this.min to="min"}}
                  {{else}}
                    {{this.min}}
                  {{/if}}
                </EuiRangeLabel>
              {{/if}}
              <EuiRangeTrack
                aria-hidden={{eq this.showInput true}}
                @disabled={{@disabled}}
                @compressed={{@compressed}}
                @max={{this.max}}
                @min={{this.min}}
                @step={{this.step}}
                @showTicks={{this.showTicks}}
                @tickInterval={{@tickInterval}}
                @ticks={{@ticks}}
                @levels={{this.levels}}
                @onChange={{this.handleOnChange}}
                @value={{@value}}
              >
                {{#if (and this.showRange this.isValid)}}
                  <EuiRangeHighlight
                    @compressed={{@compressed}}
                    @showTicks={{this.showTicks}}
                    {{!@glint-expect-error}}
                    @min={{castTo this.min to="number"}}
                    {{!@glint-expect-error}}
                    @max={{castTo this.max to="number"}}
                    {{!@glint-expect-error}}
                    @lowerValue={{castTo this.min to="number"}}
                    {{!@glint-expect-error}}
                    @upperValue={{castTo @value to="number"}}
                  />
                {{/if}}
                <EuiRangeSlider
                  aria-hidden={{if (eq this.showInput true) true false}}
                  tabindex={{if (eq this.showInput true) "-1"}}
                  @id={{if this.showInput undefined this.id}}
                  @name={{@name}}
                  @min={{this.min}}
                  @max={{this.max}}
                  @step={{this.step}}
                  @value={{@value}}
                  @disabled={{@disabled}}
                  @compressed={{@compressed}}
                  @showTicks={{this.showTicks}}
                  @showRange={{this.showRange}}
                  ...attributes
                  {{on
                    "mousedown"
                    (if
                      this.showInputOnly
                      (fn this.setPreventPopoverClose true)
                      (optional)
                    )
                  }}
                  {{on
                    "focus"
                    (if (eq this.showInput true) (optional) (optional @onFocus))
                  }}
                  {{on
                    "blur"
                    (if this.showInputOnly this.onInputBlur (optional @onBlur))
                  }}
                  {{on "input" this.handleOnChange}}
                />
                {{#if this.showRangeTooltip}}
                  <EuiRangeTooltip
                    @compressed={{@compressed}}
                    @value={{@value}}
                    @max={{this.max}}
                    @min={{this.min}}
                    @name={{@name}}
                    @showTicks={{this.showTicks}}
                  >
                    <:valuePrepend>
                      {{#if hasValuePrependBlock}}
                        {{yield to="valuePrepend"}}
                      {{else}}
                        {{@valuePrepend}}
                      {{/if}}
                    </:valuePrepend>
                    <:value>
                      {{#if hasValueBlock}}
                        {{yield to="value"}}
                      {{else}}
                        {{@value}}
                      {{/if}}
                    </:value>
                    <:valueAppend>
                      {{#if hasValueAppendBlock}}
                        {{yield to="valueAppend"}}
                      {{else}}
                        {{@valueAppend}}
                      {{/if}}
                    </:valueAppend>
                  </EuiRangeTooltip>
                {{/if}}
              </EuiRangeTrack>
              {{#if this.showLabels}}
                <EuiRangeLabel @side="max" @disabled={{@disabled}}>
                  {{#if hasMaxBlock}}
                    {{yield this.max to="max"}}
                  {{else}}
                    {{this.max}}
                  {{/if}}
                </EuiRangeLabel>
              {{/if}}
              {{#if (and this.showInput (not this.showInputOnly))}}
                <div class="euiRange__horizontalSpacer"></div>
                {{#if this.showInput}}
                  <EuiRangeInput
                    id={{this.id}}
                    @min={{this.min}}
                    @max={{this.max}}
                    @digitTolerance={{this.digitTolerance}}
                    @readOnly={{@readOnly}}
                    @step={{this.step}}
                    @value={{@value}}
                    @disabled={{@disabled}}
                    @compressed={{@compressed}}
                    @name={{@name}}
                    @fullWidth={{and this.showInputOnly this.fullWidth}}
                    @isLoading={{and this.showInputOnly @isLoading}}
                    @isInvalid={{@isInvalid}}
                    @autoSize={{not this.showInputOnly}}
                    @isPrependProvided={{hasPrepend}}
                    @isAppendProvided={{hasAppend}}
                    ...attributes
                    {{on
                      "focus"
                      (if
                        this.canShowDropdown
                        this.onInputFocus
                        (optional @onFocus)
                      )
                    }}
                    {{on
                      "blur"
                      (if
                        this.canShowDropdown this.onInputBlur (optional @onBlur)
                      )
                    }}
                    {{on "input" this.handleOnChange}}
                  >
                    <:prepend as |classes|>
                      {{yield classes to="prepend"}}
                    </:prepend>
                    <:append as |classes|>
                      {{yield classes to="append"}}
                    </:append>
                  </EuiRangeInput>
                {{/if}}
              {{/if}}
            </EuiRangeWrapper>
          </:content>
        </EuiInputPopover>
      {{else}}
        <EuiRangeWrapper
          class={{classNames
            "euiRange"
            (if this.showInput "euiRange--hasInput")
          }}
          @fullWidth={{@fullWidth}}
          @compressed={{@compressed}}
        >
          {{#if this.showLabels}}
            <EuiRangeLabel @side="min" @disabled={{@disabled}}>
              {{#if hasMinBlock}}
                {{yield this.min to="min"}}
              {{else}}
                {{this.min}}
              {{/if}}
            </EuiRangeLabel>
          {{/if}}
          <EuiRangeTrack
            aria-hidden={{eq this.showInput true}}
            @disabled={{@disabled}}
            @compressed={{@compressed}}
            @max={{this.max}}
            @min={{this.min}}
            @step={{this.step}}
            @showTicks={{this.showTicks}}
            @tickInterval={{@tickInterval}}
            @ticks={{@ticks}}
            @levels={{this.levels}}
            @onChange={{this.handleOnChange}}
            @value={{@value}}
          >
            {{#if (and this.showRange this.isValid)}}
              <EuiRangeHighlight
                @compressed={{@compressed}}
                @showTicks={{this.showTicks}}
                {{!@glint-expect-error}}
                @min={{castTo this.min to="number"}}
                {{!@glint-expect-error}}
                @max={{castTo this.max to="number"}}
                {{!@glint-expect-error}}
                @lowerValue={{castTo this.min to="number"}}
                {{!@glint-expect-error}}
                @upperValue={{castTo @value to="number"}}
              />
            {{/if}}
            <EuiRangeSlider
              aria-hidden={{if (eq this.showInput true) true false}}
              tabindex={{if (eq this.showInput true) "-1"}}
              @id={{if this.showInput undefined this.id}}
              @name={{@name}}
              @min={{this.min}}
              @max={{this.max}}
              @step={{this.step}}
              @value={{@value}}
              @disabled={{@disabled}}
              @compressed={{@compressed}}
              @showTicks={{this.showTicks}}
              @showRange={{this.showRange}}
              ...attributes
              {{on
                "mousedown"
                (if
                  this.showInputOnly (fn this.setPreventPopover true) (optional)
                )
              }}
              {{on
                "focus"
                (if (eq this.showInput true) (optional) (optional @onFocus))
              }}
              {{on
                "blur"
                (if this.showInputOnly this.onInputBlur (optional @onBlur))
              }}
              {{on "input" this.handleOnChange}}
            />
            {{#if this.showRangeTooltip}}
              <EuiRangeTooltip
                @compressed={{@compressed}}
                @value={{@value}}
                @max={{this.max}}
                @min={{this.min}}
                @name={{@name}}
                @showTicks={{this.showTicks}}
              >
                <:valuePrepend>
                  {{#if hasValuePrependBlock}}
                    {{yield to="valuePrepend"}}
                  {{else}}
                    {{@valuePrepend}}
                  {{/if}}
                </:valuePrepend>
                <:value>
                  {{#if hasValueBlock}}
                    {{yield to="value"}}
                  {{else}}
                    {{@value}}
                  {{/if}}
                </:value>
                <:valueAppend>
                  {{#if hasValueAppendBlock}}
                    {{yield to="valueAppend"}}
                  {{else}}
                    {{@valueAppend}}
                  {{/if}}
                </:valueAppend>
              </EuiRangeTooltip>
            {{/if}}
          </EuiRangeTrack>
          {{#if this.showLabels}}
            <EuiRangeLabel @side="max" @disabled={{@disabled}}>
              {{#if hasMaxBlock}}
                {{yield this.max to="max"}}
              {{else}}
                {{this.max}}
              {{/if}}
            </EuiRangeLabel>
          {{/if}}
          {{#if (and this.showInput (not this.showInputOnly))}}
            <div class="euiRange__horizontalSpacer"></div>
            {{#if this.showInput}}
              <EuiRangeInput
                id={{this.id}}
                @min={{this.min}}
                @max={{this.max}}
                @digitTolerance={{this.digitTolerance}}
                @readOnly={{@readOnly}}
                @step={{this.step}}
                @value={{@value}}
                @disabled={{@disabled}}
                @compressed={{@compressed}}
                @name={{@name}}
                @fullWidth={{and this.showInputOnly this.fullWidth}}
                @isLoading={{and this.showInputOnly @isLoading}}
                @isInvalid={{@isInvalid}}
                @autoSize={{not this.showInputOnly}}
                @isPrependProvided={{hasPrepend}}
                @isAppendProvided={{hasAppend}}
                ...attributes
                {{on
                  "focus"
                  (if
                    this.canShowDropdown this.onInputFocus (optional @onFocus)
                  )
                }}
                {{on
                  "blur"
                  (if this.canShowDropdown this.onInputBlur (optional @onBlur))
                }}
                {{on "input" this.handleOnChange}}
              >
                <:prepend as |classes|>
                  {{yield classes to="prepend"}}
                </:prepend>
                <:append as |classes|>
                  {{yield classes to="append"}}
                </:append>
              </EuiRangeInput>
            {{/if}}
          {{/if}}
        </EuiRangeWrapper>
      {{/if}}
    {{/let}}
  `, {
  strictMode: true,
  scope: () => ({
    and,
    argOrDefault,
    not,
    EuiInputPopover: EuiInputPopoverComponent,
    EuiRangeInput,
    on,
    optional,
    EuiRangeWrapper,
    classNames,
    EuiRangeLabel,
    EuiRangeTrack: EuiRangeTrackComponent,
    eq,
    EuiRangeHighlight,
    castTo,
    EuiRangeSlider,
    fn,
    EuiRangeTooltip: EuiRangeToolipComponent
  })
}), (_dec = argOrDefaultDecorator(0), _dec2 = argOrDefaultDecorator(100), _dec3 = argOrDefaultDecorator(1), _dec4 = argOrDefaultDecorator(false), _dec5 = argOrDefaultDecorator(false), _dec6 = argOrDefaultDecorator(false), _dec7 = argOrDefaultDecorator(false), _dec8 = argOrDefaultDecorator(false), _dec9 = argOrDefaultDecorator(false), _dec10 = argOrDefaultDecorator(false), _dec11 = argOrDefaultDecorator(false), _dec12 = argOrDefaultDecorator([]), (_class = class EuiRangeComponent extends Component {
  constructor(...args) {
    super(...args);
    // Defaults
    _initializerDefineProperty(this, "min", _descriptor, this);
    _initializerDefineProperty(this, "max", _descriptor2, this);
    _initializerDefineProperty(this, "step", _descriptor3, this);
    _initializerDefineProperty(this, "fullWidth", _descriptor4, this);
    _initializerDefineProperty(this, "compressed", _descriptor5, this);
    _initializerDefineProperty(this, "isLoading", _descriptor6, this);
    _initializerDefineProperty(this, "showLabels", _descriptor7, this);
    _initializerDefineProperty(this, "showInput", _descriptor8, this);
    _initializerDefineProperty(this, "showRange", _descriptor9, this);
    _initializerDefineProperty(this, "showTicks", _descriptor10, this);
    _initializerDefineProperty(this, "showValue", _descriptor11, this);
    _initializerDefineProperty(this, "levels", _descriptor12, this);
    _defineProperty(this, "preventPopoverClose", false);
    //State
    _initializerDefineProperty(this, "id", _descriptor13, this);
    _initializerDefineProperty(this, "isPopoverOpen", _descriptor14, this);
  }
  ///

  handleOnChange(e) {
    const isValid = isWithinRange(this.min, this.max, e.currentTarget.value);
    if (this.args.onChange) {
      this.args.onChange(e, isValid);
    }
  }
  get isValid() {
    return isWithinRange(this.min, this.max, this.args.value || '');
  }
  get digitTolerance() {
    return Math.max(String(this.min).length, String(this.max).length);
  }
  get showInputOnly() {
    return this.showInput === 'inputWithPopover';
  }
  get canShowDropdown() {
    return this.showInputOnly && !this.args.readOnly && !this.args.disabled;
  }
  get showRangeTooltip() {
    return this.showValue && !!String(this.args.value).length && this.args.value !== undefined;
  }
  onInputFocus(e) {
    if (this.args.onFocus) {
      this.args.onFocus(e);
    }
    this.isPopoverOpen = true;
  }
  onInputBlur(e) {
    later(this, () => {
      // Safari does not recognize any focus-related eventing for input[type=range]
      // making it impossible to capture its state using active/focus/relatedTarget
      // Instead, a prevention flag is set on mousedown, with a waiting period here.
      // Mousedown is viable because in the popover case, it is inaccessible via keyboard (intentionally)
      if (this.preventPopoverClose) {
        this.preventPopoverClose = false;
        return;
      }
      if (this.args.onBlur) {
        this.args.onBlur(e);
      }
      this.closePopover();
    }, 200);
  }
  setPreventPopover(val) {
    this.preventPopoverClose = val;
  }
  closePopover() {
    this.preventPopoverClose = false;
    this.isPopoverOpen = false;
  }
  setPreventPopoverClose(bool) {
    this.preventPopoverClose = bool;
  }
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "min", [_dec], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "max", [_dec2], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "step", [_dec3], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "fullWidth", [_dec4], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "compressed", [_dec5], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "isLoading", [_dec6], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "showLabels", [_dec7], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "showInput", [_dec8], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, "showRange", [_dec9], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, "showTicks", [_dec10], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, "showValue", [_dec11], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor12 = _applyDecoratedDescriptor(_class.prototype, "levels", [_dec12], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: null
}), _descriptor13 = _applyDecoratedDescriptor(_class.prototype, "id", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return this.args.id || guidFor({});
  }
}), _descriptor14 = _applyDecoratedDescriptor(_class.prototype, "isPopoverOpen", [tracked], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return false;
  }
}), _applyDecoratedDescriptor(_class.prototype, "handleOnChange", [action], Object.getOwnPropertyDescriptor(_class.prototype, "handleOnChange"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onInputFocus", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onInputFocus"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onInputBlur", [action], Object.getOwnPropertyDescriptor(_class.prototype, "onInputBlur"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "setPreventPopover", [action], Object.getOwnPropertyDescriptor(_class.prototype, "setPreventPopover"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "closePopover", [action], Object.getOwnPropertyDescriptor(_class.prototype, "closePopover"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "setPreventPopoverClose", [action], Object.getOwnPropertyDescriptor(_class.prototype, "setPreventPopoverClose"), _class.prototype)), _class)));

export { EuiRangeComponent as default };
//# sourceMappingURL=eui-range.js.map
