import { h, proxyCustomElement, HTMLElement, createEvent, Host } from '@stencil/core/internal/client';
import { Action, ElementIDUtils, LockManager, LockManagerOperation, SilentException, StringUtils, ApplicationContext, OVERFLOWED_CLASS_NAME, OverflowWatcher, OverflowDirection } from '@sankhyalabs/core';
import { P as PresentationMode } from './ISave.js';
import { A as AuthorizationConfig } from './AuthorizationConfig.js';
import { s as store } from './index2.js';
import { d as defineCustomElement$5 } from './snk-actions-button2.js';
import { d as defineCustomElement$4 } from './snk-data-exporter2.js';
import { d as defineCustomElement$3 } from './snk-exporter-email-sender2.js';
import { d as defineCustomElement$2 } from './taskbar-actions-button2.js';
import { d as defineCustomElement$1 } from './taskbar-split-button2.js';

var TaskbarElement;
(function (TaskbarElement) {
  TaskbarElement["PREVIOUS"] = "PREVIOUS";
  TaskbarElement["NEXT"] = "NEXT";
  TaskbarElement["REFRESH"] = "REFRESH";
  TaskbarElement["UPDATE"] = "UPDATE";
  TaskbarElement["CLONE"] = "CLONE";
  TaskbarElement["REMOVE"] = "REMOVE";
  TaskbarElement["INSERT"] = "INSERT";
  TaskbarElement["CANCEL"] = "CANCEL";
  TaskbarElement["SAVE"] = "SAVE";
  TaskbarElement["GRID_MODE"] = "GRID_MODE";
  TaskbarElement["FORM_MODE"] = "FORM_MODE";
  TaskbarElement["MORE_OPTIONS"] = "MORE_OPTIONS";
  TaskbarElement["DIVIDER"] = "DIVIDER";
  TaskbarElement["CONFIGURATOR"] = "CONFIGURATOR";
  TaskbarElement["DATA_EXPORTER"] = "DATA_EXPORTER";
  TaskbarElement["ATTACH"] = "ATTACH";
  TaskbarElement["ACTIONS_BUTTON"] = "ACTIONS_BUTTON";
  TaskbarElement["UPDATE_MULTIPLE"] = "UPDATE_MULTIPLE";
})(TaskbarElement || (TaskbarElement = {}));
var AuthorizationElements;
(function (AuthorizationElements) {
  AuthorizationElements["UPDATE"] = "UPDATE";
  AuthorizationElements["CLONE"] = "CLONE";
  AuthorizationElements["REMOVE"] = "REMOVE";
  AuthorizationElements["INSERT"] = "INSERT";
  AuthorizationElements["CONFIGURATOR"] = "CONFIGURATOR";
})(AuthorizationElements || (AuthorizationElements = {}));
var VisibleWhenForbidden;
(function (VisibleWhenForbidden) {
  VisibleWhenForbidden["CONFIGURATOR"] = "CONFIGURATOR";
})(VisibleWhenForbidden || (VisibleWhenForbidden = {}));
const buildCustomButton = (def, className, dataElementId, action, isEnabled) => {
  const { hint, text, iconName } = def;
  if (iconName) {
    if (text) {
      return iconTextButton(iconName, def.name, className, dataElementId, hint, text, action, isEnabled);
    }
    else {
      return iconButton(iconName, def.name, className, dataElementId, hint, action, isEnabled);
    }
  }
  else {
    return textButton(def.name, className, dataElementId, text, hint, action, isEnabled);
  }
};
const buildElem = (element, className, dataElementId, getTitle, action, isEnabled, actions, dataExporterStoreKey, presentationMode) => {
  var _a;
  const title = getTitle(element);
  switch (element) {
    case TaskbarElement.PREVIOUS:
      return iconButton("chevron-left", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.NEXT:
      return iconButton("chevron-right", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.REFRESH:
      return iconButton("sync", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.UPDATE:
      return iconButton("edit", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.UPDATE_MULTIPLE:
      return iconButton("edit-table", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.CLONE:
      return iconButton("copy", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.REMOVE:
      return iconButton("delete", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.INSERT:
      if (presentationMode === PresentationMode.PRIMARY) {
        return iconTextButton("plus", element, className, dataElementId, title, title, action, isEnabled);
      }
      else {
        return iconButton("plus", element, className, dataElementId, title, action, isEnabled);
      }
    case TaskbarElement.CANCEL:
      return textButton(element, className, dataElementId, title, title, action, isEnabled);
    case TaskbarElement.SAVE:
      if (presentationMode === PresentationMode.PRIMARY) {
        return iconTextButton("save", element, className, dataElementId, title, title, action, isEnabled);
      }
      else {
        return iconButton("save", element, className, dataElementId, title, action, isEnabled);
      }
    case TaskbarElement.GRID_MODE:
      return iconButton("table", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.FORM_MODE:
      return iconButton("list", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.CONFIGURATOR:
      if ((actions === null || actions === void 0 ? void 0 : actions.length) > 0) {
        return splitButton("settings-inverted", element, className, title, dataElementId, isEnabled, actions, action);
      }
      return iconButton("settings-inverted", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.MORE_OPTIONS:
      return actionButton(element, className, dataElementId, title, isEnabled, actions, action);
    case TaskbarElement.DIVIDER:
      return h("hr", { class: "ez-divider-vertical ez-divider--dark ez-margin--none ez-margin-left--medium", "data-taskbar-divider": true });
    case TaskbarElement.DATA_EXPORTER:
      const provider = (_a = store.get("exporterProviders")) === null || _a === void 0 ? void 0 : _a[dataExporterStoreKey];
      return h("snk-data-exporter", { class: className, provider: provider, "data-element-id": dataElementId, "data-taskbar-element": element });
    case TaskbarElement.ATTACH:
      return iconButton("anexo", element, className, dataElementId, title, action, isEnabled);
    case TaskbarElement.ACTIONS_BUTTON:
      return h("snk-actions-button", { "data-element-id": dataElementId, "data-taskbar-element": element });
  }
};
function textButton(name, className, dataElementId, text, title, action, isEnabled) {
  return h("ez-button", { key: dataElementId, title: title, label: text, size: "small", class: className, "data-taskbar-label": text, "data-taskbar-element": name, "data-element-id": dataElementId, enabled: isEnabled(name), onClick: () => action(name) });
}
function iconButton(iconName, name, className, dataElementId, title, action, isEnabled) {
  return h("ez-button", { key: dataElementId, title: title, mode: "icon", size: "small", class: className, "data-taskbar-label": title, "data-taskbar-element": name, "data-taskbar-icon": iconName, "data-element-id": dataElementId, iconName: iconName, enabled: isEnabled(name), onClick: () => action(name) });
}
function iconTextButton(iconName, name, className, dataElementId, text, title, action, isEnabled) {
  return h("ez-button", { key: dataElementId, title: title, label: text, size: "small", class: className, "data-taskbar-label": text, "data-taskbar-icon": iconName, "data-taskbar-element": name, "data-element-id": dataElementId, enabled: isEnabled(name), onClick: () => action(name) },
    h("ez-icon", { class: "ez-padding-right--small", slot: "leftIcon", iconName: iconName }));
}
function splitButton(iconName, element, className, title, dataElementId, isEnabled, actions, action) {
  return actions && actions.length > 0
    ? h("taskbar-split-button", { iconName: iconName, class: className, key: dataElementId, "data-taskbar-icon": iconName, "data-taskbar-label": title, "data-taskbar-element": element, "data-element-id": dataElementId, enabled: isEnabled(element), actions: actions, title: title, action: () => action(element) })
    : undefined;
}
function actionButton(element, className, dataElementId, title, isEnabled, actions, action) {
  return actions && actions.length > 0
    ? h("taskbar-actions-button", { class: className, key: dataElementId, title: title, "data-taskbar-element": element, "data-element-id": dataElementId, enabled: isEnabled(element), actions: actions, onTaskbarActionSelected: (evt) => action(evt.detail.value) })
    : undefined;
}

const snkTaskbarCss = ".sc-snk-taskbar-h{display:flex;flex-wrap:wrap}.no-wrap.sc-snk-taskbar-h{flex-wrap:nowrap}.full-width.sc-snk-taskbar-h{width:100%}.align-right.sc-snk-taskbar-h{justify-content:flex-end}.overflowed.sc-snk-taskbar{display:none}";

const SnkTaskbar = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.actionClick = createEvent(this, "actionClick", 7);
    this.taskbarSaveLocker = createEvent(this, "taskbarSaveLocker", 7);
    this.taskbarSaveUnlocker = createEvent(this, "taskbarSaveUnlocker", 7);
    this.TASKBAR_ITEM_ID_PREFIX = 'TASKBAR_ITEM_';
    this.TASKBAR_CUSTOM_ELEMENTS_CONTAINER_CLASS_NAME = 'taskbar-custom-elements-container';
    this.ACTIONS_BUTTON_TAG = 'TASKBAR-ACTIONS-BUTTON';
    this.NOT_OVERFLOW_ELEMENTS = ["moreOptions", "dataExporter_snkDataExporter", "actionsButton_snkActionsButton"];
    this.TASKBAR_CUSTOM_ELEMENTS = 'taskbar-custom-elements-container';
    this._dataUnitInitialized = false;
    this._titleKeyByElement = {
      [TaskbarElement.UPDATE_MULTIPLE]: "snkTaskbar.titleUpdateMultiple",
      [TaskbarElement.UPDATE]: "snkTaskbar.titleUpdate",
      [TaskbarElement.PREVIOUS]: "snkTaskbar.titlePrevious",
      [TaskbarElement.NEXT]: "snkTaskbar.titleNext",
      [TaskbarElement.REFRESH]: "snkTaskbar.titleRefresh",
      [TaskbarElement.CLONE]: "snkTaskbar.titleClone",
      [TaskbarElement.REMOVE]: "snkTaskbar.titleRemove",
      [TaskbarElement.MORE_OPTIONS]: "snkTaskbar.titleMoreOptions",
      [TaskbarElement.INSERT]: "snkTaskbar.titleInsert",
      [TaskbarElement.CANCEL]: "snkTaskbar.titleCancel",
      [TaskbarElement.SAVE]: "snkTaskbar.titleSave",
      [TaskbarElement.GRID_MODE]: "snkTaskbar.titleGridMode",
      [TaskbarElement.FORM_MODE]: "snkTaskbar.titleFormMode",
      [TaskbarElement.CONFIGURATOR]: "snkTaskbar.titleConfigurator",
      [TaskbarElement.ATTACH]: "snkTaskbar.titleAttach",
    };
    this.onSaveEvent = (action) => {
      switch (action.type) {
        case Action.FIELD_INVALIDATED:
        case Action.INVALIDATE_CLEAN:
        case Action.DATA_SAVED:
        case Action.SAVING_ERROR:
        case Action.SAVING_CANCELED:
          this._isWaitingForSave = false;
          break;
        case Action.SAVING_DATA:
          this._isWaitingForSave = true;
          break;
      }
    };
    this._permissions = undefined;
    this._overFlowedElements = [];
    this._customElements = undefined;
    this._customElementsId = undefined;
    this._slotContainer = undefined;
    this._hiddenActionsList = [];
    this._lastWidth = undefined;
    this._hasToUpdateOverFlow = false;
    this._isWaitingForSave = false;
    this.alignRigth = false;
    this.customSlotId = "TASKBAR_CUSTOM_ELEMENTS";
    this.customContainerId = undefined;
    this.overflowStrategy = 'hiddenItems';
    this.configName = undefined;
    this.resourceID = undefined;
    this.buttons = undefined;
    this.customButtons = undefined;
    this.actionsList = undefined;
    this.actionsSettingsList = undefined;
    this.primaryButton = undefined;
    this.disabledButtons = undefined;
    this.dataUnit = undefined;
    this.presentationMode = PresentationMode.PRIMARY;
    this.messagesBuilder = undefined;
  }
  handleCustomSlotElementsLoaded(event) {
    if (this.hasToSearchCustomElements(event)) {
      this.getCustomElements(true);
    }
  }
  handleTaskbarSaveLocker() {
    if (this._isWaitingForSave !== true) {
      this._isWaitingForSave = true;
    }
  }
  handleTaskbarSaveUnlocker() {
    if (this._isWaitingForSave === true) {
      this._isWaitingForSave = false;
    }
  }
  hasToSearchCustomElements(event) {
    return this.customSlotId === event.detail && !this._slotContainer;
  }
  observeButtons() {
    this._definitions = undefined;
    requestAnimationFrame(() => {
      requestAnimationFrame(() => { var _a; return (_a = this._overFlowWatcher) === null || _a === void 0 ? void 0 : _a.forceUpdate(); });
    });
  }
  observeDisabledButtons() {
    var _a;
    (_a = this._overFlowWatcher) === null || _a === void 0 ? void 0 : _a.forceUpdate();
  }
  observeLastWidth(newValue, oldValue) {
    if (oldValue === 0 && newValue !== 0) {
      this._hasToUpdateOverFlow = true;
    }
  }
  observeIsWaitingForSave(newValue, oldValue) {
    if (newValue == true && oldValue == false) {
      this.taskbarSaveLocker.emit();
    }
    if (newValue == false && oldValue == true) {
      this.taskbarSaveUnlocker.emit();
    }
  }
  observeDataUnit(newValue) {
    this.initializeDataUnit(newValue);
  }
  initializeDataUnit(dataUnit) {
    if (!!dataUnit && !this._dataUnitInitialized) {
      this._dataUnitInitialized = true;
      const dataInfo = { dataUnit: this.dataUnit };
      ElementIDUtils.addIDInfo(this._element, null, dataInfo);
      this.dataUnit.subscribe(this.onSaveEvent);
    }
  }
  // Internal methods
  elementsFromString(strButtons) {
    const elements = [];
    if (strButtons == null)
      return elements;
    strButtons.split(",").forEach(buttonName => {
      buttonName = buttonName.trim();
      if (VisibleWhenForbidden[buttonName] || this.isAllowed(buttonName)) {
        elements.push(buttonName.trim());
      }
    });
    return elements;
  }
  isAllowed(buttonName) {
    if (buttonName === AuthorizationElements.CONFIGURATOR) {
      return this._permissions
        ? this._permissions.isSup
          || this._permissions[AuthorizationConfig.CONFIG_GRID]
          || this._permissions[AuthorizationConfig.CONFIG]
        : false;
    }
    if (AuthorizationElements[buttonName]) {
      return this._permissions ? this._permissions.isSup || this._permissions[buttonName] : false;
    }
    return true;
  }
  /**
   * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
   * através de um pequeno modulo na estrutura da aplicação:
   * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
   * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-taskbar.msg.ts"
   */
  getTitle(element) {
    var _a;
    let key;
    if (this.isAllowed(element)) {
      key = this._titleKeyByElement[element];
    }
    else {
      key = "snkTaskbar.forbidden";
    }
    return key ? (_a = this.messagesBuilder) === null || _a === void 0 ? void 0 : _a.getMessage(key, {}) : "";
  }
  elementClick(elem) {
    LockManager.whenResolve(this._element, LockManagerOperation.TASKBAR_CLICK).then(() => {
      if (!this.dataUnit) {
        return;
      }
      switch (elem) {
        case TaskbarElement.PREVIOUS:
          this.dataUnit.previousRecord();
          break;
        case TaskbarElement.NEXT:
          this.dataUnit.nextRecord();
          break;
        case TaskbarElement.REFRESH:
          this.dataUnit.loadData();
          break;
        case TaskbarElement.CLONE:
          this.dataUnit.copySelected();
          break;
        case TaskbarElement.REMOVE:
          this.dataUnit.removeSelectedRecords();
          break;
        case TaskbarElement.INSERT:
          this.dataUnit.addRecord();
          break;
        case TaskbarElement.CANCEL:
          this.dataUnit.cancelEdition();
          break;
        case TaskbarElement.SAVE:
          if (!this._isWaitingForSave) {
            this._isWaitingForSave = true;
            this.dataUnit.saveData().catch((err) => {
              if (err instanceof SilentException) {
                return;
              }
              else {
                throw err;
              }
            }).finally(() => {
              this._isWaitingForSave = false;
            });
          }
          break;
      }
      if (this.isEnabled(elem))
        this.actionClick.emit(elem);
    });
  }
  isEnabled(elem) {
    if (!this.isAllowed(elem)) {
      return false;
    }
    return !(this.disabledButtons && this.disabledButtons.includes(elem));
  }
  validatePresentationMode() {
    if (Object.values(PresentationMode).includes(this.presentationMode)) {
      return;
    }
    this.presentationMode = PresentationMode.PRIMARY;
  }
  getElement(index, def) {
    let className = def === this.primaryButton ? "ez-button--primary " : "";
    if (index > 1) {
      className += "ez-padding-left--medium";
    }
    const taskbarElement = TaskbarElement[def.toString()];
    const dataExporterStoreKey = this._element.dataset.exporterStoreKey || this.configName;
    if (taskbarElement) {
      return buildElem(def, className, this.getIdElemBtnNative(def), elem => this.getTitle(elem), elem => this.elementClick(elem), elem => this.isEnabled(elem), def !== TaskbarElement.CONFIGURATOR ? this.buildDynamicActionsList() : this.buildActionsSettingsList(), dataExporterStoreKey, this.presentationMode);
    }
    else {
      return buildCustomButton(def, className, this.getIdElemBtnCustom(def), elem => this.elementClick(elem), elem => this.isEnabled(elem));
    }
  }
  buildDynamicActionsList() {
    var _a;
    if (this._hiddenActionsList.length) {
      return [...((_a = this.actionsList) !== null && _a !== void 0 ? _a : []), ...this._hiddenActionsList];
    }
    return this.actionsList;
  }
  buildActionsSettingsList() {
    return this.actionsSettingsList;
  }
  getIdElemBtnNative(taskbarElem) {
    return StringUtils.toCamelCase(taskbarElem);
  }
  getIdElemBtnCustom(btnCustom) {
    return StringUtils.toCamelCase(btnCustom.name);
  }
  isDivider(element) {
    var _a;
    if (element === undefined) {
      return false;
    }
    return (_a = element.$attrs$) === null || _a === void 0 ? void 0 : _a["data-taskbar-divider"];
  }
  removeEmpty(elements) {
    let lastElem;
    return elements.filter(elem => {
      if (elem == undefined) {
        return false;
      }
      if (this.isDivider(lastElem) && this.isDivider(elem)) {
        return false;
      }
      lastElem = elem;
      return true;
    });
  }
  appendCustomElementsInTaskbar() {
    this._customElementsId.forEach(id => {
      const elementId = id.replace(this.TASKBAR_ITEM_ID_PREFIX, '');
      const customElement = this._customElements.get(elementId);
      const container = this._element.querySelector(`#${id}`);
      if (container) {
        container === null || container === void 0 ? void 0 : container.appendChild(customElement);
      }
      else {
        this.unlinkCustomElementFromTaskbar(customElement);
      }
    });
  }
  addCustomElementContainer(elem) {
    var _a;
    const elementId = `${this.TASKBAR_ITEM_ID_PREFIX}${elem}`;
    if (!this._customElementsId.includes(elementId)) {
      this._customElementsId.push(elementId);
      (_a = this._overFlowWatcher) === null || _a === void 0 ? void 0 : _a.addNotOverFlowElement(elementId);
    }
    return h("span", { class: "ez-padding-left--medium", key: elementId, id: elementId });
  }
  getCustomElements(searchOnDocument) {
    var _a, _b;
    this._customElementsId = [];
    this._customElements = new Map();
    this._slotContainer = this.buildSlotContainer(searchOnDocument);
    const customElementsArray = Array.from((_b = (_a = this._slotContainer) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : []);
    customElementsArray.forEach(item => this._customElements.set(item.id, item));
  }
  buildSlotContainer(searchOnDocument) {
    let slotContainer;
    if (this.customContainerId) {
      const container = document.querySelector(`#${this.customContainerId}`);
      slotContainer = container === null || container === void 0 ? void 0 : container.querySelector(`#${this.customSlotId}`);
    }
    else {
      slotContainer = this._element.querySelector(`#${this.customSlotId}`);
    }
    // Caso nõa encontre o slot container dentro do próprio elemento, tenta buscar na DOM do document.
    if (searchOnDocument && !slotContainer) {
      slotContainer = document.querySelector(`#${this.customSlotId}`);
    }
    return slotContainer;
  }
  componentWillLoad() {
    this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
    if (this._application) {
      this._application.getAllAccess(this.resourceID).then(access => this._permissions = access);
    }
    else {
      this._permissions = {};
    }
    this.getCustomElements();
  }
  componentWillRender() {
    this.handleDefinitions();
    this.validatePresentationMode();
    this.updateOverFlowIfNeeded();
  }
  handleDefinitions() {
    if (this._definitions == undefined && this._permissions) {
      this._definitions = this.elementsFromString(this.buttons);
    }
  }
  updateOverFlowIfNeeded() {
    if (this._hasToUpdateOverFlow) {
      requestAnimationFrame(() => { var _a; return (_a = this._overFlowWatcher) === null || _a === void 0 ? void 0 : _a.forceUpdate(); });
      this._hasToUpdateOverFlow = false;
    }
  }
  handleOverFlow(overFlowingElements) {
    const elementsToHandle = overFlowingElements.filter(element => !this.hasToIgnoreOverFlow(element));
    this.resetOverFlowedElements();
    this.doOverFlowElements(elementsToHandle);
  }
  resetOverFlowedElements() {
    this._overFlowedElements.forEach(element => {
      element.classList.remove(OVERFLOWED_CLASS_NAME);
    });
    this._hiddenActionsList = [];
    this._overFlowedElements = [];
  }
  doOverFlowElements(overFlowedElements) {
    overFlowedElements.forEach(element => {
      element.classList.add(OVERFLOWED_CLASS_NAME);
      this._overFlowedElements.push(element);
      this.addItemToActionList(element);
    });
  }
  addItemToActionList(element) {
    const taskbarElement = this.getTaskbarElementName(element);
    if (taskbarElement && this.isEnabled(taskbarElement) && this.isAllowed(taskbarElement)) {
      const optionItem = {
        value: taskbarElement,
        label: this.getTaskbarElementLabel(element),
        iconName: this.getTaskbarElementIcon(element)
      };
      this._hiddenActionsList.push(optionItem);
    }
  }
  getTaskbarElementName(element) {
    var _a;
    return (_a = element.getAttribute('data-taskbar-element')) !== null && _a !== void 0 ? _a : "";
  }
  getTaskbarElementIcon(element) {
    var _a;
    return (_a = element.getAttribute('data-taskbar-icon')) !== null && _a !== void 0 ? _a : "";
  }
  getTaskbarElementLabel(element) {
    var _a;
    return (_a = element.getAttribute('data-taskbar-label')) !== null && _a !== void 0 ? _a : "";
  }
  hasToIgnoreOverFlow(element) {
    return element.classList.contains(this.TASKBAR_CUSTOM_ELEMENTS_CONTAINER_CLASS_NAME);
  }
  handleOverFlowStrategy() {
    if (this.overflowStrategy === 'hiddenItems') {
      this._overFlowWatcher = new OverflowWatcher(this.buildOverFlowWatcherParams());
    }
  }
  buildOverFlowWatcherParams() {
    return {
      element: this._element,
      callback: this.handleOverFlow.bind(this),
      overFlowDirection: OverflowDirection.HORIZONTAL,
      notOverFlow: this.NOT_OVERFLOW_ELEMENTS
    };
  }
  componentDidLoad() {
    this.initializeDataUnit(this.dataUnit);
    this.handleOverFlowStrategy();
  }
  componentDidRender() {
    this.appendCustomElementsInTaskbar();
    this.updateLastWidth();
  }
  updateLastWidth() {
    this._lastWidth = this._element.getBoundingClientRect().width;
  }
  disconnectedCallback() {
    var _a, _b;
    (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.unsubscribe(this.onSaveEvent);
    this.unlinkAllCustomElements();
    (_b = this._overFlowWatcher) === null || _b === void 0 ? void 0 : _b.destroy();
  }
  unlinkAllCustomElements() {
    var _a;
    (_a = this._customElementsId) === null || _a === void 0 ? void 0 : _a.forEach(id => {
      const elementId = id.replace(this.TASKBAR_ITEM_ID_PREFIX, '');
      const customElement = this._customElements.get(elementId);
      this.unlinkCustomElementFromTaskbar(customElement);
    });
  }
  unlinkCustomElementFromTaskbar(customElement) {
    this._slotContainer.appendChild(customElement);
  }
  render() {
    var _a;
    if (this._definitions === undefined) {
      return undefined;
    }
    let index = 0;
    return (h(Host, { class: this.getHostClasses() }, this.removeEmpty(this._definitions.map((elem) => {
      var _a, _b;
      index++;
      if (TaskbarElement[elem]) {
        return this.getElement(index, TaskbarElement[elem]);
      }
      if ((_a = this.customButtons) === null || _a === void 0 ? void 0 : _a.has(elem)) {
        return this.getElement(index, this.customButtons.get(elem));
      }
      if (this._customElements.has(elem)) {
        return this.addCustomElementContainer(elem);
      }
      (_b = this._overFlowWatcher) === null || _b === void 0 ? void 0 : _b.addNotOverFlowElement(elem);
      return h("slot", { name: elem });
    })), h("div", { id: this.TASKBAR_CUSTOM_ELEMENTS, class: this.TASKBAR_CUSTOM_ELEMENTS_CONTAINER_CLASS_NAME }, h("slot", { name: this.customSlotId }), (_a = this._overFlowWatcher) === null || _a === void 0 ? void 0 :
      _a.addNotOverFlowElement(this.TASKBAR_CUSTOM_ELEMENTS))));
  }
  getHostClasses() {
    if (this.overflowStrategy !== 'hiddenItems')
      return 'no-wrap';
    return `full-width ${this.alignRigth ? 'align-right' : ""}`;
  }
  get _element() { return this; }
  static get watchers() { return {
    "buttons": ["observeButtons"],
    "disabledButtons": ["observeDisabledButtons"],
    "_lastWidth": ["observeLastWidth"],
    "_isWaitingForSave": ["observeIsWaitingForSave"],
    "dataUnit": ["observeDataUnit"]
  }; }
  static get style() { return snkTaskbarCss; }
}, [6, "snk-taskbar", {
    "alignRigth": [4, "align-rigth"],
    "customSlotId": [1, "custom-slot-id"],
    "customContainerId": [1, "custom-container-id"],
    "overflowStrategy": [1, "overflow-strategy"],
    "configName": [1, "config-name"],
    "resourceID": [1, "resource-i-d"],
    "buttons": [1],
    "customButtons": [16],
    "actionsList": [16],
    "actionsSettingsList": [16],
    "primaryButton": [1, "primary-button"],
    "disabledButtons": [16],
    "dataUnit": [16],
    "presentationMode": [1537, "presentation-mode"],
    "messagesBuilder": [1040],
    "_permissions": [32],
    "_overFlowedElements": [32],
    "_customElements": [32],
    "_customElementsId": [32],
    "_slotContainer": [32],
    "_hiddenActionsList": [32],
    "_lastWidth": [32],
    "_hasToUpdateOverFlow": [32],
    "_isWaitingForSave": [32]
  }, [[8, "snkCustomSlotElementsLoaded", "handleCustomSlotElementsLoaded"], [8, "taskbarSaveLocker", "handleTaskbarSaveLocker"], [8, "taskbarSaveUnlocker", "handleTaskbarSaveUnlocker"]]]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["snk-taskbar", "snk-actions-button", "snk-data-exporter", "snk-exporter-email-sender", "taskbar-actions-button", "taskbar-split-button"];
  components.forEach(tagName => { switch (tagName) {
    case "snk-taskbar":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, SnkTaskbar);
      }
      break;
    case "snk-actions-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "snk-data-exporter":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "snk-exporter-email-sender":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "taskbar-actions-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "taskbar-split-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}

export { SnkTaskbar as S, TaskbarElement as T, defineCustomElement as d };
