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, VegaSlimmer } from 'vega-slimmer/core';
import { MonthPeriod } from '../../../../../helpers/calendar';
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import { Icons } from '../../../assets/icons';
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';
export class VegaDatePickerCalendarHeaderRenderer extends VegaSlimmer {
  render() {
    return (h("vega-flex", { class: "month-item-header", alignItems: "center" },
      this.renderSwitcher(),
      this.yearMonthSwitcherRender.render()));
  }
  renderSwitcher() {
    return (h("vega-flex", { gap: "size-8", alignItems: "center" },
      this.renderPrevIcon(),
      this.renderToday(),
      this.renderNextIcon()));
  }
  renderPrevIcon() {
    const startDate = this.currentPeriod.current.firstDateOfMonth();
    const isDisabled = this.minCalendarDate &&
      (startDate.isBefore(this.minCalendarDate) || startDate.equal(this.minCalendarDate));
    return (h("vega-button-circle", { class: {
        'button-previous-month': true,
        'disabled': isDisabled,
      }, variant: "icon-only", icon: VegaInternalIconManager.getIconKey('chevron-left'), "data-aria-label": this.translationSlimmer.t('Previous month'), ref: (ref) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
          this.currentPeriodController.gotoPreviousPeriod();
        });
      }, iconColor: isDisabled ? 'text-disabled' : 'text-link', size: this.getNavigationIconSize(), disabled: isDisabled }));
  }
  renderNextIcon() {
    const period = this.isDualMonths ? this.currentPeriod.next() : this.currentPeriod;
    const endDate = period.current.lastDateOfMonth();
    const isDisabled = this.maxCalendarDate &&
      (endDate.isAfter(this.maxCalendarDate) || endDate.equal(this.maxCalendarDate));
    return (h("vega-button-circle", { class: {
        'button-next-month': true,
        'disabled': isDisabled,
      }, variant: "icon-only", icon: VegaInternalIconManager.getIconKey('chevron-right'), "data-aria-label": this.translationSlimmer.t('Next month'), ref: (ref) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
          this.currentPeriodController.gotoNextPeriod();
        });
      }, size: this.getNavigationIconSize(), iconColor: isDisabled ? 'text-disabled' : 'text-link', disabled: isDisabled }));
  }
  renderToday() {
    const hasLabel = this.isDualMonths && this.size !== 'small';
    return (h("vega-button-link", { class: {
        'button-today': true,
        'with-label': hasLabel,
      }, "data-aria-label": this.translationSlimmer.t('Today'), label: hasLabel ? this.translationSlimmer.t('Today') : '', ref: (ref) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
          this.currentPeriodController.updateCalendarPeriod(new MonthPeriod(this.today, true, this.timezone));
        });
      }, size: this.size === 'large' ? 'default' : 'small', icon: VegaInternalIconManager.getIconKey('bulls-eye') }));
  }
  getNavigationIconSize() {
    if (this.size === 'large')
      return 'small';
    return 'extra-small';
  }
}
(() => {
  VegaInternalIconManager.register({
    'chevron-left': Icons['chevron-left'],
    'chevron-right': Icons['chevron-right'],
    'bulls-eye': Icons['bulls-eye'],
  });
})();
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "currentPeriod", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "today", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "translationSlimmer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "yearMonthSwitcherRender", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "currentPeriodController", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "maxCalendarDate", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "minCalendarDate", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "size", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "timezone", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerCalendarHeaderRenderer.prototype, "isDualMonths", void 0);
