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 { Component, Element, h, Host, Prop, State } from '@stencil/core';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer } from 'vega-slimmer/core';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../../helpers/slimmers/component-usage-runtime-metrics';
import { sanitizeVegaComponent } from '../../../utils/component';
import ChangeManager from '../../../helpers/change-manager/change-manager';
import { Observer } from '../../../helpers/change-manager/observer/observer';
import { SIDENAV_LINK_SELECTED_TOPIC } from '../../../helpers/change-manager/subject/static-subject/static-subject-title';
import { createEnterKeyHandlerToTriggerClick } from '../../../utils/accessibility';
import { VegaSidenavGroupSubStateController } from './slimmers/controllers/vega-sidenav-group-sub-state-controller';
import { isHTMLVegaSidenavLinkElement } from '../utils';
/**
 * @deprecated This component will be removed soon, please consider using `vega-left-nav-group` component instead.
 * @vegaVersion 1, v2.29.0
 */
export class VegaSidenavGroup {
  constructor() {
    this.subStateObserverSlimmer = new VegaSidenavGroupSubStateController();
    this.globalSlimmers = {};
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.openState = 'close';
    /**
     * Specifies the text that serves as the label or title
     *    for the side navigation group in the sidebar.
     *
     * @vegaVersion 1, v2.29.0
     */
    this.label = '';
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-sidenav-group-toggle}
     */
    this.handleClick = (e) => {
      const currentTarget = e.currentTarget;
      if (currentTarget && currentTarget.dataset.root === '$1') {
        e.preventDefault();
        currentTarget.closest('.vega-li-main').classList.toggle('open');
      }
    };
  }
  /**
   * The below method is e2e-test covered in
   * @see{module:vega-sidenav-group-e2e-disconnected}
   */
  /* istanbul ignore next */
  disconnectedCallback() {
    ChangeManager.unregister(SIDENAV_LINK_SELECTED_TOPIC, this.observer);
  }
  componentWillLoad() {
    this.observer = new Observer(isHTMLVegaSidenavLinkElement, this.observerListener.bind(this));
    ChangeManager.register(SIDENAV_LINK_SELECTED_TOPIC, this.observer);
  }
  render() {
    return sanitizeVegaComponent(h(Host, null,
      h("div", { class: { 'vega-li-main': true, 'sidenav-open': this.openState !== 'close' }, ref: (ref) => (this.groupContainer = ref) },
        h("a", { href: `#${this.label}`, role: 'button', tabIndex: 0, onKeyDown: createEnterKeyHandlerToTriggerClick(), "data-root": "$1", onClick: this.handleClick, "aria-label": this.label || 'No label defined' },
          h("div", { class: "vega-links-icon" },
            h("div", { class: "prefix-icon" },
              h("vega-icon", { icon: this.icon, size: "size-24" }))),
          h("span", { class: "vega-links-name" }, this.label),
          h("div", { class: "suffix-icons" },
            h("vega-icon", { icon: "chevron-down", size: "size-12" }),
            h("vega-icon", { icon: "chevron-up", size: "size-12" }))),
        h("div", { class: "vega-nav-list vega-nav-list-sub" },
          h("slot", null)))), this.host);
  }
  /**
   * The below method is e2e-test covered in
   * @see{module:vega-sidenav-group-observer-with-selected}
   */
  /* istanbul ignore next */
  observerListener(castInput) {
    const hasSelectedLinkItem = this.host.contains(castInput);
    if (hasSelectedLinkItem) {
      this.groupContainer.querySelector('a').classList.add('sub-selected');
      this.groupContainer.classList.add('open');
    }
    else {
      this.groupContainer.querySelector('a').classList.remove('sub-selected');
      this.groupContainer.classList.remove('open');
    }
  }
  static get is() { return "vega-sidenav-group"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-sidenav-group.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-sidenav-group.css"]
  }; }
  static get properties() { return {
    "icon": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1, v2.29.0"
          }],
        "text": "Represents the icon attached to the side navigation\n   group header link."
      },
      "attribute": "icon",
      "reflect": false
    },
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1, v2.29.0"
          }],
        "text": "Specifies the text that serves as the label or title\n   for the side navigation group in the sidebar."
      },
      "attribute": "label",
      "reflect": false,
      "defaultValue": "''"
    }
  }; }
  static get states() { return {
    "openState": {}
  }; }
  static get elementRef() { return "host"; }
}
__decorate([
  InjectVegaSlimmer()
], VegaSidenavGroup.prototype, "subStateObserverSlimmer", void 0);
__decorate([
  InjectVegaGlobalSlimmer()
], VegaSidenavGroup.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSidenavGroup.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
