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 changeManager from '../../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { findParent } from '../../../../../utils/ui';
import { VegaInternalLeftNavLinkClick, VegaInternalLeftNavLinkSelected, } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
export class VegaLeftNavLinkRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-left-nav-link-click-event}
     */
    /* istanbul ignore next */
    this.handleClick = () => {
      if (!this.selected && !this.customSelectionEnabled) {
        this.controller.setSelected(true);
      }
      this.menuClickEventEmitter.emit();
      this.notifyVegaLeftNav();
      this.notifyVegaLeftGroup();
    };
  }
  render() {
    const url = this.url || 'javascript:void(0);';
    const classList = this.selected === true ? 'selected' : '';
    return (h(Host, { class: classList, "data-key": this.itemKey },
      h("a", { href: url, target: this.target, onClick: this.handleClick },
        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" },
          h("slot", null)),
        !!this.deprecatedPropertySlimmer.getValue() && (h("div", { class: "vega-counter-badge" },
          h("vega-counter-badge", { count: this.deprecatedPropertySlimmer.getValue(), color: this.counterBadge.color }))))));
  }
  notifyVegaLeftNav() {
    const vegaLeftNav = findParent(this.host, 'vega-left-nav');
    if (vegaLeftNav) {
      changeManager.notify(domNodeSubjectFactory.getSubject(vegaLeftNav, VegaInternalLeftNavLinkClick), {
        host: this.host,
      });
    }
  }
  notifyVegaLeftGroup() {
    const topParent = this.vegaLeftNavHierarchyController.getTopParent();
    if (topParent) {
      changeManager.notify(domNodeSubjectFactory.getSubject(topParent, VegaInternalLeftNavLinkSelected), {
        host: this.host,
      });
    }
  }
}
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "selected", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "url", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "counterBadge", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "icon", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "menuClickEventEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "controller", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "deprecatedPropertySlimmer", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "customSelectionEnabled", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "itemKey", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "target", void 0);
__decorate([
  MapToComponentField()
], VegaLeftNavLinkRenderer.prototype, "vegaLeftNavHierarchyController", void 0);
