var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
export class VegaInputRangeClearIconRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * Set the component value to empty and focus on the first input element
     */
    this.clearInputRangeValue = () => {
      this.valueController.setValue(['', '']);
      this.inputRangeInputRenderer.focusFirstInput();
    };
  }
  /**
   * This function renders a clear icon element for an input range with specific styling and event handlers.
   *
   * @returns {HTMLElement} the clear button
   */
  render() {
    return (h("div", { class: {
        'vega-input-range-clear-icon': true,
        'invisible': !this.shouldShowClearIcon(),
      }, "aria-label": "clear input range", role: "button", tabindex: !this.disabled ? 0 : -1, onClick: this.clearInputRangeValue, onKeyDown: createEnterKeyHandlerToTriggerClick() },
      h("vega-icon", { icon: "close" })));
  }
  /**
   * It is responsible for determining whether the clear icon should be displayed based on certain conditions.
   *
   * @returns {boolean} boolean result
   */
  shouldShowClearIcon() {
    return (this.showClearIcon &&
      !this.disabled &&
      Array.isArray(this.value) &&
      this.value.some((item) => !!item));
  }
}
__decorate([
  MapToComponentField()
], VegaInputRangeClearIconRenderer.prototype, "showClearIcon", void 0);
__decorate([
  MapToComponentField()
], VegaInputRangeClearIconRenderer.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaInputRangeClearIconRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaInputRangeClearIconRenderer.prototype, "inputRangeInputRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaInputRangeClearIconRenderer.prototype, "valueController", void 0);
