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 { 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 changeManager from '../../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalDatePickerCalendarClear } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
import { buildDatePickerAnnouncement } from '../../../../../helpers/calendar/utils';
export class VegaDatePickerCalendarRenderer extends VegaSlimmer {
  render() {
    return (h("div", { class: {
        'calendar': true,
        'static-height': this.staticHeight,
      } },
      h("div", { class: "container__main" },
        this.headerRenderer.render(),
        this.renderContainer(),
        this.renderFooter()),
      h("div", { class: "aria-announcement", "aria-live": "polite", "aria-atomic": "true" }, this.buildAnnouncement())));
  }
  renderContainer() {
    return (h("div", { class: "container__months" }, this.isDualMonths ? this.renderRangeMonth() : this.monthItemRenderer.render('start')));
  }
  renderRangeMonth() {
    return (h(Fragment, null,
      this.monthItemRenderer.render('start'),
      this.monthItemRenderer.render('end')));
  }
  renderFooter() {
    return (this.clearButton && (h("div", { class: "footer-container" },
      h("vega-button-link", { ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
            this.clearCalendar();
          });
        }, label: this.translationSlimmer.t('Clear') }))));
  }
  clearCalendar() {
    this.clearEventEmitter.emit();
    changeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalDatePickerCalendarClear), {});
  }
  /**
   * Build aria announcement string based on current calendar selection.
   *
   * @returns {string} - Aria announcement string.
   */
  buildAnnouncement() {
    const { startDate, endDate } = this.calendarSelection;
    return buildDatePickerAnnouncement({
      mode: this.mode,
      startDate,
      endDate,
    });
  }
}
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "clearButton", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "calendarSelection", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "monthItemRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "staticHeight", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "translationSlimmer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "mode", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "clearEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "headerRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarRenderer.prototype, "isDualMonths", void 0);
