import { Component, Host, h, Prop, State, Element, Event, Watch } from '@stencil/core';
export class UxplTreeNav {
  constructor() {
    // Set the delimitter in selectionKey. eg) menu1>menu1.1>menu1.1.1
    this.selectionKeyDelimitter = '>';
    // Override the name of the id attribute for each menu item in the TreeConfig model
    this.idAttribute = 'id';
    this.expanded = true;
  }
  handleSelectParentByIdChange(newValue, oldValue) {
    if (newValue !== oldValue) {
      this.uxplSelection.emit(this.el.id + '-' + newValue);
    }
  }
  expand(expand, e) {
    this.expanded = expand;
    e.stopPropagation();
  }
  render() {
    var _a, _b;
    if ((_a = this.el) === null || _a === void 0 ? void 0 : _a.id) {
      return (h(Host, null, this.expanded ?
        h("div", { class: "treenav-container" },
          h("div", { class: "menu-items" }, (_b = this.config) === null || _b === void 0 ? void 0 : _b.map((menuItem) => {
            var _a;
            return h("uxpl-tree-menu-item", { config: menuItem, "selection-key": this.selectionKey, "selection-key-delimitter": this.selectionKeyDelimitter, "id-attribute": this.idAttribute, "tree-id": (_a = this.el) === null || _a === void 0 ? void 0 : _a.id });
          })),
          h("div", { class: "treenav-collapse", onClick: (e) => this.expand(false, e) },
            h("div", { class: "collapse-element" },
              h("span", { class: "collapse-text" }, "Collapse"),
              h("uxpl-icon", { class: "collapse-icon", size: "24px", icon: "pl-icon-collapse-horizontal" }))))
        :
          h("div", { class: "treenav-collapsed", onClick: (e) => this.expand(true, e) },
            h("uxpl-icon", { class: "collapse-icon reversed", size: "24px", icon: "pl-icon-collapse-horizontal" }))));
    }
    else
      return 'You must give this component an id';
  }
  static get is() { return "uxpl-tree-nav"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["uxpl-tree-nav.css"]
  }; }
  static get styleUrls() { return {
    "$": ["uxpl-tree-nav.css"]
  }; }
  static get properties() { return {
    "config": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "TreeConfig[]",
        "resolved": "TreeConfig[]",
        "references": {
          "TreeConfig": {
            "location": "import",
            "path": "../../models/treeNav"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "selectParentById": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "select-parent-by-id",
      "reflect": false
    },
    "selectionKey": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "selection-key",
      "reflect": false
    },
    "selectionKeyDelimitter": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "selection-key-delimitter",
      "reflect": false,
      "defaultValue": "'>'"
    },
    "idAttribute": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "id-attribute",
      "reflect": false,
      "defaultValue": "'id'"
    }
  }; }
  static get states() { return {
    "expanded": {}
  }; }
  static get events() { return [{
      "method": "uxplSelection",
      "name": "uxplSelection",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }]; }
  static get elementRef() { return "el"; }
  static get watchers() { return [{
      "propName": "selectParentById",
      "methodName": "handleSelectParentByIdChange"
    }]; }
}
