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 { VegaSlimmer, MapToComponentField } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
/* The code is defining a class called `VegaTimePickerRangeClearButtonRenderer` that extends the `VegaSlimmer` class. This class is used to render a clear button for a time picker range component. */
export class VegaTimePickerRangeClearButtonRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /** The `onClickClearIcon` function is a private method that is called when the clear icon is clicked. It performs the following actions: */
    this.onClickClearIcon = () => {
      this.valueController.clearRangeTimePicker();
      this.endDropdownController.hide();
      void this.rangeInputRenderer.getStartInputRef().doFocus();
    };
  }
  render() {
    return (h("div", { class: {
        'vega-time-picker-range-clear-icon': true,
        'invisible': !this.shouldShowClearButton(),
      }, "aria-label": "clear input", role: "button", tabindex: !this.disabled ? 0 : -1, onClick: this.onClickClearIcon, onKeyDown: createEnterKeyHandlerToTriggerClick() },
      h("vega-icon", { icon: "close", class: "v-min-w-min vega-flex-shrink-0" })));
  }
  /**
   * Determines whether the range clear button should be visible. The button
   * is shown only when the clear icon feature is enabled, the component is
   * not disabled, and at least one end of the range value is non-empty.
   *
   * @returns {boolean} `true` when the clear button should be visible.
   */
  shouldShowClearButton() {
    return (this.showClearIcon &&
      !this.disabled &&
      Array.isArray(this.value) &&
      (Boolean(this.value[0]) || Boolean(this.value[1])));
  }
}
__decorate([
  MapToComponentField()
], VegaTimePickerRangeClearButtonRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerRangeClearButtonRenderer.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerRangeClearButtonRenderer.prototype, "showClearIcon", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerRangeClearButtonRenderer.prototype, "valueController", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerRangeClearButtonRenderer.prototype, "endDropdownController", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerRangeClearButtonRenderer.prototype, "rangeInputRenderer", void 0);
