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 { Fragment, h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
import { isArrayEqual } from '../../../../utils/array';
/**
 * Date picker input base renderer
 */
export class VegaDatePickerInputRendererBase extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.onClickClearIcon = async () => {
      if (this.mode === 'range') {
        this.vegaDatePickerValueController.setValue(['', '']);
      }
      else {
        this.vegaDatePickerValueController.setValue('');
      }
      if (this.isCalendarShow) {
        await this.calendarOpenStateController.hideCalendar();
      }
      this.focusInput();
    };
    this.isClearIconVisible = () => {
      if (this.mode === 'range') {
        const value = this.vegaDatePickerValueController.getValue();
        return !this.disabled && !isArrayEqual(value, ['', '']);
      }
      else {
        const value = this.vegaDatePickerValueController.getValue();
        return !this.disabled && Boolean(value.length);
      }
    };
  }
  /**
   * Render clear icon for either single or range date picker
   */
  renderClearIcon() {
    return (h(Fragment, null, this.showClearIcon && this.isClearIconVisible() && (h("div", { class: "vega-input-clear-icon", tabIndex: -1, "aria-label": "clear input", role: "button", onClick: this.onClickClearIcon, onKeyDown: createEnterKeyHandlerToTriggerClick() },
      h("vega-icon", { icon: "close" })))));
  }
}
__decorate([
  MapToComponentField()
], VegaDatePickerInputRendererBase.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerInputRendererBase.prototype, "showClearIcon", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerInputRendererBase.prototype, "mode", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerInputRendererBase.prototype, "isCalendarShow", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerInputRendererBase.prototype, "vegaDatePickerValueController", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerInputRendererBase.prototype, "calendarOpenStateController", void 0);
