'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-a7b0c73d.js');
const core = require('@sankhyalabs/core');
const EzScrollDirection = require('./EzScrollDirection-b2c99895.js');
const index$1 = require('./index-1be40f19.js');

const ezGuideNavigatorCss = ":host{--ez-guide-navigator--padding-left:var(--space--large);--ez-guide-navigator--padding-right:var(--space--small);--ez-guide-navigator--box-shadow:var(--shadow, 0px 0px 24px 0px #000);--ez-guide-navigator--background-color:var(--color--inverted);--ez-guide-navigator--border-radius:0px var(--border--radius-medium) var(--border--radius-medium) 0px;--ez-guide-navigator--actions-gap:var(--space--medium);--ez-guide-navigator--actions-margin:var(--space--large) 0 var(--space--medium);--ez-guide-navigator--actions-padding-right:calc(var(--space--medium, 12px) + var(--space--small, 6px))}.inverted{transform:rotate(180deg)}.ez-guide-navigator{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;height:100%;padding-left:var(--ez-guide-navigator--padding-left);padding-right:var(--ez-guide-navigator--padding-right);background-color:var(--ez-guide-navigator--background-color);-webkit-box-shadow:var(--ez-guide-navigator--box-shadow);box-shadow:var(--ez-guide-navigator--box-shadow);border-radius:var(--ez-guide-navigator--border-radius)}.ez-guide-navigator__actions{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:var(--ez-guide-navigator--actions-gap);margin:var(--ez-guide-navigator--actions-margin);padding-right:var(--ez-guide-navigator--actions-padding-right)}.hidden{display:none}";

const ENTER_KEY = "Enter";
const EzGuideNavigator = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ezSelectionChange = index.createEvent(this, "ezSelectionChange", 7);
    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 index$1.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() {
    core.ElementIDUtils.addIDInfoIfNotExists(this._element);
    return (index.h(index.Host, null, index.h("ez-sidebar-button", { class: this.open ? "hidden" : "", onEzClick: this.handleToggleSidebar.bind(this), "aria-controls": "navigator", "aria-expanded": this.open, "data-element-id": core.ElementIDUtils.getInternalIDInfo("openButton") }), index.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": core.ElementIDUtils.getInternalIDInfo("sidebar") }, index.h("div", { role: "search", class: "ez-guide-navigator__actions" }, index.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": core.ElementIDUtils.getInternalIDInfo("textinput") }), index.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": core.ElementIDUtils.getInternalIDInfo("closeButton") })), index.h("ez-scroller", { direction: EzScrollDirection.EzScrollDirection.VERTICAL, activeShadow: true }, index.h("ez-tree", { ref: element => (this._tree = element), items: this.items, "data-element-id": core.ElementIDUtils.getInternalIDInfo("tree"), tooltipResolver: this.tooltipResolver, onEzChange: evt => this.ezSelectionChange.emit(evt.detail), selectedId: this.selectedId })))));
  }
  get _element() { return index.getElement(this); }
};
EzGuideNavigator.style = ezGuideNavigatorCss;

exports.ez_guide_navigator = EzGuideNavigator;
