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, Host } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { arrayToClassString } from '../../../../utils/ui';
import { DomNodeSubjectObserverFactory } from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick } from '../../../../helpers/event-manager/event-id/vega-event-id';
import { Icons } from '../../assets/icons';
import { VegaInternalIconManager } from '../../../../helpers/icon/internal-icon-manager';
export class VegaDatePickerRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.renderInputPrefix = () => {
      return (h("div", { class: "vega-input-prefix", "aria-hidden": "true" },
        h("vega-icon", { icon: VegaInternalIconManager.getIconKey('calendar'), color: "text-secondary", 
          // eslint-disable-next-line react/jsx-no-bind
          onClick: async () => {
            if (!this.disabled) {
              await this.focusInput();
              await this.vegaDatePickerCalendarRenderer.triggerRepick('start');
            }
          } })));
    };
    /**
     * return true if input is enabled, otherwise false
     * on mobile, the input is ready-only to avoid virtual keyboard
     */
    this.isInputEnabled = () => {
      return !this.readOnly && !this.isMobileDevice;
    };
    this.renderLabel = () => {
      return (this.label && (h("vega-field-label", { ref: (e) => {
          /* istanbul ignore next */
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(e, VegaClick, async () => {
            await this.focusInput();
          });
        }, isFieldRequired: this.required, disabled: this.disabled, label: this.label })));
    };
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-date-picker-click-label-focus-input-e2e}
     */
    /* istanbul ignore next */
    this.focusInput = async () => {
      var _a, _b;
      (_a = this.vegaDatePickerSingleInputRenderer.getSingleDateInputRef()) === null || _a === void 0 ? void 0 : _a.focus();
      (_b = this.vegaDatePickerRangeInputRenderer.getStartDateInputRef()) === null || _b === void 0 ? void 0 : _b.focus();
      await this.calendarOpenStateController.showCalendar();
    };
  }
  getDatePickerContainer() {
    return this.datePickerContainer;
  }
  render() {
    const classNames = [
      'vega-input-container',
      this.size,
      `${this.mode}-mode`,
      this.isMobileDevice ? /* istanbul ignore next */ 'mobile' : '',
    ];
    return (h(Host, { class: {
        disabled: this.disabled,
      } },
      this.renderLabel(),
      h("div", { class: arrayToClassString(classNames), ref: (ref) => (this.datePickerContainer = ref) }, this.mode === 'range'
        ? this.vegaDatePickerRangeInputRenderer.render()
        : this.vegaDatePickerSingleInputRenderer.render()),
      this.vegaDatePickerCalendarRenderer.render()));
  }
}
(() => {
  VegaInternalIconManager.register({ calendar: Icons.calendar });
})();
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "size", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "mode", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "label", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "required", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "readOnly", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "autoValidation", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "isMobileDevice", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "vegaDatePickerSingleInputRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "vegaDatePickerRangeInputRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "vegaDatePickerCalendarRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerRenderer.prototype, "calendarOpenStateController", void 0);
