import { h, Host } from "@stencil/core";
import { ElementIDUtils } from "@sankhyalabs/core";
import { EzScrollDirection } from "../ez-scroller/EzScrollDirection";
import initI18n from '../../utils/i18n';
const ENTER_KEY = "Enter";
export class EzGuideNavigator {
  constructor() {
    this.open = true;
    this.selectedId = undefined;
    this.items = [];
    this.tooltipResolver = undefined;
    this.filterText = "";
  }
  /**
   * Desabilita um ou mais itens.
   */
  async disableItem(id) {
    [].concat(id).forEach(item => this._tree.disableItem(item));
  }
  /**
   * Abre o navegador de Guia
   */
  async openGuideNavidator() {
    this.open = true;
  }
  /**
   * Habilita um ou mais itens.
   */
  async enableItem(id) {
    [].concat(id).forEach(item => this._tree.enableItem(item));
  }
  /**
   * Atualiza um ou mais items
   */
  async updateItem(item) {
    [].concat(item).forEach(item => this._tree.updateItem(item));
  }
  /**
   * Obtem um item pelo id
   */
  async getItem(id) {
    return this._tree.getItem(id);
  }
  /**
   * Obtem um array do caminho de itens da seleção atual.
   * @returns Retorna um array do caminho de itens da seleção atual.
   */
  async getCurrentPath() {
    var _a;
    return (_a = this._tree) === null || _a === void 0 ? void 0 : _a.getCurrentPath();
  }
  /**
   * Seleciona o item desejado pelo ID.
   * @param id - ID do item que receberá a seleção.
   */
  async selectGuide(id) {
    if (this._tree == undefined || id == undefined) {
      return;
    }
    this._tree.selectItem(id);
    this.getCurrentPath()
      .then((currentPath) => {
      currentPath === null || currentPath === void 0 ? void 0 : currentPath.forEach((item) => {
        this._tree.openItem(item.id);
      });
    });
  }
  /**
   * Obtem o item pai a partir de um id
   */
  async getParent(id) {
    return this._tree.getParent(id);
  }
  async componentWillLoad() {
    this.i18n = await initI18n();
  }
  async handleToggleSidebar() {
    this.open = !this.open;
  }
  handleFilterTree(event) {
    if (event.key === ENTER_KEY) {
      this._tree.applyFilter(this.filterText);
    }
  }
  onFilterChanged(event) {
    this.filterText = event.detail;
    event.stopPropagation();
  }
  render() {
    ElementIDUtils.addIDInfoIfNotExists(this._element);
    return (h(Host, null, h("ez-sidebar-button", { class: this.open ? "hidden" : "", onEzClick: this.handleToggleSidebar.bind(this), "aria-controls": "navigator", "aria-expanded": this.open, "data-element-id": ElementIDUtils.getInternalIDInfo("openButton") }), h("aside", { tabIndex: -1, id: "navigator", class: "ez-col ez-col--sd-12 ez-col--tb-3 ez-guide-navigator " + (this.open ? "" : "hidden"), "data-element-id": ElementIDUtils.getInternalIDInfo("sidebar") }, h("div", { role: "search", class: "ez-guide-navigator__actions" }, h("ez-filter-input", { mode: "slim", value: this.filterText, onEzChange: (event) => this.onFilterChanged(event), label: this.i18n("ez-guide-navigator.searchGuide"), "aria-placeholder": this.i18n("ez-guide-navigator.searchGuide"), onKeyUp: this.handleFilterTree.bind(this), "data-element-id": ElementIDUtils.getInternalIDInfo("textinput") }), h("ez-button", { onClick: this.handleToggleSidebar.bind(this), class: "inverted", mode: "icon", size: "small", iconName: "show_menu", title: this.i18n("ez-guide-navigator.hideMenu"), "aria-label": this.i18n("ez-guide-navigator.hideMenu"), "aria-controls": "navigator", "data-element-id": ElementIDUtils.getInternalIDInfo("closeButton") })), h("ez-scroller", { direction: EzScrollDirection.VERTICAL, activeShadow: true }, h("ez-tree", { ref: element => (this._tree = element), items: this.items, "data-element-id": ElementIDUtils.getInternalIDInfo("tree"), tooltipResolver: this.tooltipResolver, onEzChange: evt => this.ezSelectionChange.emit(evt.detail), selectedId: this.selectedId })))));
  }
  static get is() { return "ez-guide-navigator"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["ez-guide-navigator.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["ez-guide-navigator.css"]
    };
  }
  static get properties() {
    return {
      "open": {
        "type": "boolean",
        "mutable": true,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define se o menu de navega\u00E7\u00E3o est\u00E1 aberto."
        },
        "attribute": "open",
        "reflect": true,
        "defaultValue": "true"
      },
      "selectedId": {
        "type": "string",
        "mutable": true,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define o id do item selecionado."
        },
        "attribute": "selected-id",
        "reflect": true
      },
      "items": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "Array<IGuideItem>",
          "resolved": "IGuideItem[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Lista de itens do menu de navega\u00E7\u00E3o."
        },
        "defaultValue": "[]"
      },
      "tooltipResolver": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "(item: IGuideItem, enabled: boolean, level: number) => string",
          "resolved": "(item: IGuideItem, enabled: boolean, level: number) => string",
          "references": {
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define uma fun\u00E7\u00E3o que vai resolver o `tooltip` ou `title` daquele item."
        }
      }
    };
  }
  static get states() {
    return {
      "filterText": {}
    };
  }
  static get events() {
    return [{
        "method": "ezSelectionChange",
        "name": "ezSelectionChange",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Evento emitido quando o item selecionado no navigator \u00E9 alterado."
        },
        "complexType": {
          "original": "IGuideItem",
          "resolved": "IGuideItem",
          "references": {
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            }
          }
        }
      }];
  }
  static get methods() {
    return {
      "disableItem": {
        "complexType": {
          "signature": "(id: string | Array<string>) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "Array": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Desabilita um ou mais itens.",
          "tags": []
        }
      },
      "openGuideNavidator": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Abre o navegador de Guia",
          "tags": []
        }
      },
      "enableItem": {
        "complexType": {
          "signature": "(id: string | Array<string>) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "Array": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Habilita um ou mais itens.",
          "tags": []
        }
      },
      "updateItem": {
        "complexType": {
          "signature": "(item: IGuideItem | Array<IGuideItem>) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            },
            "Array": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Atualiza um ou mais items",
          "tags": []
        }
      },
      "getItem": {
        "complexType": {
          "signature": "(id: string) => Promise<IGuideItem>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            }
          },
          "return": "Promise<IGuideItem>"
        },
        "docs": {
          "text": "Obtem um item pelo id",
          "tags": []
        }
      },
      "getCurrentPath": {
        "complexType": {
          "signature": "() => Promise<Array<IGuideItem>>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            },
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            },
            "Array": {
              "location": "global"
            }
          },
          "return": "Promise<IGuideItem[]>"
        },
        "docs": {
          "text": "Obtem um array do caminho de itens da sele\u00E7\u00E3o atual.",
          "tags": [{
              "name": "returns",
              "text": "Retorna um array do caminho de itens da sele\u00E7\u00E3o atual."
            }]
        }
      },
      "selectGuide": {
        "complexType": {
          "signature": "(id: string) => Promise<void>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "id - ID do item que receber\u00E1 a sele\u00E7\u00E3o."
                }],
              "text": "- ID do item que receber\u00E1 a sele\u00E7\u00E3o."
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "Array": {
              "location": "global"
            },
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Seleciona o item desejado pelo ID.",
          "tags": [{
              "name": "param",
              "text": "id - ID do item que receber\u00E1 a sele\u00E7\u00E3o."
            }]
        }
      },
      "getParent": {
        "complexType": {
          "signature": "(id: string) => Promise<IGuideItem>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "IGuideItem": {
              "location": "import",
              "path": "./interfaces"
            }
          },
          "return": "Promise<IGuideItem>"
        },
        "docs": {
          "text": "Obtem o item pai a partir de um id",
          "tags": []
        }
      }
    };
  }
  static get elementRef() { return "_element"; }
}
