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 { DomNodeSubjectObserverFactory } from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaChange, VegaClick, VegaDropdownClick, } from '../../../../../helpers/event-manager/event-id/vega-event-id';
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import chevronRight from '../../../../../global/icons/chevron-right';
import chevronLeft from '../../../../../global/icons/chevron-left';
import ellipsisVertical from '../../../icons/ellipsis-vertical';
/** The `VegaCalendarSwitchPanelRenderer` class in TypeScript React renders a calendar switch panel with date navigation, view selection, and action buttons. */
export class VegaCalendarSwitchPanelRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * This function is responsible for updating the `viewMode` property of the `VegaCalendarSwitchPanelRenderer` class with the value extracted from the `input` parameter.
     *
     * @param {NotifyObserverPayload<VegaCalendarViewModeType>} input mark which view should be selected
     */
    this.handleViewChange = (input) => {
      this.currentPeriodController.updateCalendarPeriod(input.detail, this.postOperationDate);
    };
    /**
     * reset view content to today
     */
    this.todayButtonClick = () => {
      this.currentPeriodController.setCurrentPeriod(this.currentPeriod.now());
    };
    /**
     * update view content after click next button
     */
    this.nextButtonClick = () => {
      this.currentPeriodController.setCurrentPeriod(this.currentPeriod.next());
    };
    /**
     * update view content after click previous button
     */
    this.prevButtonClick = () => {
      this.currentPeriodController.setCurrentPeriod(this.currentPeriod.previous());
    };
    /**
     * The more action menu item click
     *
     * @param {NotifyObserverPayload<string>} payload The object contains the menu item key
     */
    this.moreActionMenuClick = (payload) => {
      this.moreActionClickEmitter.emit(payload.detail);
    };
  }
  /**
   * get the switch panel container element
   *
   * @returns {HTMLVegaFlexElement} container element
   */
  getSwitchPanelRef() {
    return this.switchPanelRef;
  }
  /**
   * calendar switch panel with date switch, view switch, add new button, and more action components.
   *
   * @returns {HTMLElement} html element
   */
  render() {
    return (h("vega-flex", { direction: "row", gap: "size-16", justifyContent: "space-between", alignItems: "center", class: "calendar-switch-panel", ref: (node) => (this.switchPanelRef = node) },
      this.renderDateSwitch(),
      h("div", { class: "calendar-view-switch-container" },
        this.showSwitchView ? this.renderViewSwitch() : null,
        this.renderMoreActionMenu())));
  }
  /**
   * The `renderDateSwitch` function returns a container with buttons for switching dates and displaying the current date.
   *
   * @returns {HTMLDivElement} action button elements container.
   */
  renderDateSwitch() {
    return (h("div", { class: "calendar-date-switch-container" },
      h("vega-button", { variant: "secondary", size: "small", ref: (button) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(button, VegaClick, this.todayButtonClick);
        }, label: this.translationSlimmer.t('Today') }),
      h("vega-button-circle", { variant: "secondary", size: "small", icon: VegaInternalIconManager.getIconKey('chevron-left'), label: "previous", showTooltip: false, ref: (button) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(button, VegaClick, this.prevButtonClick);
        } }),
      h("vega-button-circle", { variant: "secondary", size: "small", icon: VegaInternalIconManager.getIconKey('chevron-right'), label: "next", showTooltip: false, ref: (button) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(button, VegaClick, this.nextButtonClick);
        } }),
      this.renderCurrentPeriod()));
  }
  /**
   * The function `renderCurrentPeriod` returns an HTML element displaying the view date content summary info.
   *
   * @returns {HTMLVegaFontElement} The text content inside the element is "Current Date Test".
   */
  renderCurrentPeriod() {
    return (h("vega-font", { class: "calendar-current-date", variant: "font-field-label", color: "text-primary" }, this.getViewDateSummary()));
  }
  /**
   * The function `renderViewSwitch` returns a JSX element for rendering a segment control component in a TypeScript React application.
   *
   * @returns {HTMLElement} An HTMLElement containing a vega-segment-control element with specific attributes and event handling.
   */
  renderViewSwitch() {
    return (h("vega-segment-control", { segments: VegaCalendarSwitchPanelRenderer.views.map((item) => (Object.assign(Object.assign({}, item), { text: this.translationSlimmer.t(item.text) }))), size: "small", variant: "text-only", selected: this.viewMode, ref: (node) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaChange, this.handleViewChange);
      } }));
  }
  /**
   * Render an more action button if dropdown source is not empty
   *
   * @returns {Nullable<HTMLElement>} the additional element
   */
  renderMoreActionMenu() {
    var _a, _b;
    if ((_b = (_a = this.moreActionDropdownProps) === null || _a === void 0 ? void 0 : _a.source) === null || _b === void 0 ? void 0 : _b.length) {
      return (h("vega-dropdown", Object.assign({ alignment: "end", trigger: "click" }, this.moreActionDropdownProps, { ref: (node) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaDropdownClick, this.moreActionMenuClick);
        } }),
        h("vega-button-circle", { "data-aria-label": this.translationSlimmer.t('More actions'), size: "small", icon: VegaInternalIconManager.getIconKey('ellipsis-vertical'), variant: "icon-only" })));
    }
  }
  /**
   * Get the view content date summary info, such as `January, 2024` or `10 January, 2024` or `28 December, 2023 - 3 January, 2024`
   *
   * @returns {string} string
   */
  getViewDateSummary() {
    const currentDate = this.currentPeriod.current;
    let result = '';
    switch (this.viewMode) {
      case 'day': {
        const monthName = this.translationSlimmer.t(currentDate.getMonthName());
        result = `${currentDate.date} ${monthName}, ${currentDate.year}`;
        break;
      }
      case 'week': {
        const weekItems = this.calendarView.dateItems[0];
        const start = weekItems[0];
        const end = weekItems[weekItems.length - 1];
        const [startMonthName, endMonthName] = [start, end].map((item) => this.translationSlimmer.t(item.getMonthName()));
        result = `${start.date} ${startMonthName}${start.year === end.year ? '' : ', ' + start.year} - ${end.date} ${endMonthName}, ${end.year}`;
        break;
      }
      case 'month': {
        const monthName = this.translationSlimmer.t(currentDate.getMonthName());
        result = `${monthName}, ${currentDate.year}`;
        break;
      }
    }
    return result;
  }
}
(() => {
  VegaInternalIconManager.register({
    'chevron-right': chevronRight,
    'chevron-left': chevronLeft,
    'ellipsis-vertical': ellipsisVertical,
  });
})();
VegaCalendarSwitchPanelRenderer.views = [
  { text: 'Day', key: 'day' },
  { text: 'Week', key: 'week' },
  { text: 'Month', key: 'month' },
];
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "viewMode", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "calendarView", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "currentPeriod", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "moreActionDropdownProps", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "moreActionClickEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "currentPeriodController", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "calendarViewController", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "translationSlimmer", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "postOperationDate", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarSwitchPanelRenderer.prototype, "showSwitchView", void 0);
