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 chevronUp from '../../../../../global/icons/chevron-up';
import chevronDown from '../../../../../global/icons/chevron-down';
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import changeManager from '../../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalLeftNavGroupExpand } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
export class VegaLeftNavGroupRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.handleClick = (e) => {
      const currentTarget = e.currentTarget;
      if (currentTarget && currentTarget.dataset.root === '$1') {
        e.preventDefault();
        this.vegaLeftNavGroupOpenStateController.toggle();
        const isExpand = this.vegaLeftNavGroupOpenStateController.isOpen();
        this.groupClickEventEmitter.emit(isExpand ? 'EXPAND' : 'COLLAPSE');
        this.notifyOtherGroup();
      }
    };
  }
  /**
   * Get the map of the row form refs
   *
   * @returns {HTMLDivElement} The map of row form refs
   */
  getGroupContainer() {
    return this.groupContainer;
  }
  render() {
    return (h("div", { class: `vega-li-main ${this.openByDefault ? 'open' : ''}`, ref: (ref) => (this.groupContainer = ref) },
      h("a", { href: `#${this.label}`, role: 'button', tabIndex: 0, "data-root": "$1", onClick: this.handleClick, "aria-label": this.label || 'No label defined' },
        this.icon && (h("div", { class: "vega-links-icon" },
          h("div", { class: "prefix-icon" },
            h("vega-icon", { icon: this.icon, size: "size-16" })))),
        h("span", { class: "vega-links-name" }, this.label),
        h("div", { class: "suffix-icons" },
          h("vega-icon", { icon: VegaInternalIconManager.getIconKey('chevron-down'), size: "size-12" }),
          h("vega-icon", { icon: VegaInternalIconManager.getIconKey('chevron-up'), size: "size-12" }))),
      h("div", { class: "vega-nav-list-sub" },
        h("slot", null))));
  }
  /**
   * Notify other left nav groups to collapse
   */
  notifyOtherGroup() {
    const topParent = this.vegaLeftNavHierarchyController.getTopParent();
    if (topParent) {
      changeManager.notify(domNodeSubjectFactory.getSubject(topParent, VegaInternalLeftNavGroupExpand), { host: this.host });
    }
  }
}
(() => {
  VegaInternalIconManager.register({
    'chevron-up': chevronUp,
    'chevron-down': chevronDown,
  });
})();
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "autoCollapseGroups", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "icon", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "label", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "groupClickEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "vegaLeftNavHierarchyController", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "openByDefault", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "itemKey", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavGroupRenderer.prototype, "vegaLeftNavGroupOpenStateController", void 0);
