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 } from 'vega-slimmer/core';
import { LogUtility } from '../../../../utils/log';
import { VegaDatePickerInputRendererBase } from './vega-date-picker-input-renderer-base.abstract';
import { CalendarDate } from '../../../../helpers/calendar';
export class VegaDatePickerSingleInputRenderer extends VegaDatePickerInputRendererBase {
  constructor() {
    super(...arguments);
    this.render = () => {
      return (h("div", { class: "date-picker-input" },
        this.vegaDatePickerRenderer.renderInputPrefix(),
        h("input", { readOnly: !this.vegaDatePickerRenderer.isInputEnabled(), placeholder: this.getSinglePlaceholder(), value: this.vegaDatePickerValueController.getValue(), ref: (ref) => (this.singleDateInputRef = ref), onChange: this.onSingleDateChange, disabled: this.disabled, role: "combobox", "aria-label": this.label
            ? `${this.label}, ${this.translationSlimmer.t('date picker')}`
            : this.translationSlimmer.t('date picker'), "aria-haspopup": "dialog", "aria-expanded": `${this.isCalendarShow}`, "aria-controls": this.vegaDatePickerCalendarRenderer.getCalendarId(), 
          /* eslint-disable-next-line react/jsx-no-bind */
          onClick: () => this.calendarOpenStateController.showCalendar() }),
        this.renderClearIcon()));
    };
    this.getSinglePlaceholder = () => {
      if (!this.placeholder) {
        return this.format;
      }
      if (typeof this.placeholder !== 'string') {
        LogUtility.warn('The placeholder should be a string');
        return this.format;
      }
      return this.placeholder;
    };
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-date-picker-single-date-change}
     */
    this.onSingleDateChange = (e) => {
      const currentTarget = e.currentTarget;
      const date = currentTarget.value;
      if (CalendarDate.fromString(date, this.format)) {
        this.vegaDatePickerValueController.setValue(this.vegaDatePickerFormatController.formatDate(date));
      }
      else {
        this.vegaDatePickerValueController.setValue('');
        this.singleDateInputRef.value = '';
        LogUtility.warn('The date value of ${date} is invalid');
      }
    };
  }
  getSingleDateInputRef() {
    return this.singleDateInputRef;
  }
  focusInput() {
    this.singleDateInputRef.focus();
  }
}
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "placeholder", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "format", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "label", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "isCalendarShow", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "vegaDatePickerFormatController", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "vegaDatePickerRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "calendarOpenStateController", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "vegaDatePickerCalendarRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerSingleInputRenderer.prototype, "translationSlimmer", void 0);
