"use strict";exports.__esModule = true;exports.MenuNavigation = void 0;var









MenuNavigation = exports.MenuNavigation = /*#__PURE__*/function () {







  function MenuNavigation(root, itemsContentDataTid) {var _this = this;this.tagsAndItems = new WeakMap();this.highlightedItem = null;this.items = [];this.






















































































    getEnabledItems = function () {
      return _this.items.filter(function (item) {return item.isEnabled();});
    };this.root = root;this.itemsContentDataTid = itemsContentDataTid;}var _proto = MenuNavigation.prototype;_proto.update = function update() {var _this$root,_this2 = this;if ((_this$root = this.root) != null && _this$root.current) {var menuItems = Array.from(this.root.current.querySelectorAll("span[data-tid=\"" + this.itemsContentDataTid + "\"]"));this.items = menuItems.map(function (item) {return _this2.tagsAndItems.get(item);}).filter(function (item) {return item !== undefined;});}};_proto.add = function add(tag, item) {var _this$root2;this.tagsAndItems.set(tag, item);if ((_this$root2 = this.root) != null && _this$root2.current) {this.update();} else {this.items.push(item);}};_proto.remove = function remove(tag) {this.tagsAndItems.delete(tag);this.update();};_proto.move = function move(step, isCyclic) {var enabledItems = this.getEnabledItems();var currentIndex = this.highlightedItem ? enabledItems.indexOf(this.highlightedItem) : -1;var minIndex = 0;var maxIndex = enabledItems.length - 1;var nextIndex = currentIndex + step;if (nextIndex < minIndex) {nextIndex = isCyclic ? maxIndex : minIndex;}if (nextIndex > maxIndex) {nextIndex = isCyclic ? minIndex : maxIndex;}var nextItem = enabledItems[nextIndex];this.highlight(nextItem);return nextIndex;};_proto.highlight = function highlight(item) {var _this3 = this;var enabledItems = this.getEnabledItems();enabledItems.forEach(function (_item) {if (item === _item) {_item.highlight();_this3.highlightedItem = item;} else {_item.unhighlight();}});};_proto.highlightByIndex = function highlightByIndex(index) {var _this4 = this;this.items.forEach(function (_item, i) {if (index === i && _item.isEnabled()) {_item.highlight();_this4.highlightedItem = _item;} else {_item.unhighlight();}});};_proto.unhighlight = function unhighlight() {var _this$highlightedItem;(_this$highlightedItem = this.highlightedItem) == null || _this$highlightedItem.unhighlight();this.highlightedItem = null;};_proto.select = function select(event) {if (this.highlightedItem) {this.highlightedItem.select(event);return true;}return false;};_proto.reset = function reset() {this.highlight(null);this.highlightedItem = null;};return MenuNavigation;}();