'use strict';

class TaskbarProcessor {
  constructor(defaultButtons) {
    this._defaultButtons = defaultButtons;
  }
  process(taskbarId, taskbarManager, dataState, disabledButtons = [], invisibleButtons = []) {
    var _a;
    this.customButtons = new Map();
    this.buttons = "";
    this.disabledButtons = [].concat(disabledButtons);
    (_a = this.getButtonsArray(taskbarId, taskbarManager, dataState)) === null || _a === void 0 ? void 0 : _a.forEach(btnDef => {
      let buttonName;
      if (typeof btnDef === "string") {
        buttonName = btnDef;
      }
      else {
        const customBtn = btnDef;
        this.customButtons.set(customBtn.name, customBtn);
        buttonName = customBtn.name;
      }
      if (!invisibleButtons.includes(buttonName)) {
        if (!this.isEnabled(taskbarId, taskbarManager, buttonName, dataState, disabledButtons)) {
          this.disabledButtons.push(buttonName);
        }
        if (this.buttons.length > 0) {
          this.buttons += ",";
        }
        this.buttons += buttonName;
      }
    });
  }
  getButtonsArray(taskbarId, taskbarManager, dataState) {
    const defaults = this.getButtonsFromKey(taskbarId);
    if (taskbarManager) {
      return taskbarManager.getButtons(taskbarId, dataState, [...defaults]);
    }
    return defaults;
  }
  getButtonsFromKey(taskbarId) {
    const btnsValue = this._defaultButtons[taskbarId];
    return typeof btnsValue === 'function' ? btnsValue() : btnsValue;
  }
  isEnabled(taskbarId, taskbarManager, buttonName, dataState, disabled) {
    const originalValue = disabled.includes(buttonName) ? false : true;
    if (taskbarManager && taskbarManager.isEnabled) {
      return taskbarManager.isEnabled(taskbarId, dataState, buttonName, originalValue);
    }
    return originalValue;
  }
}

exports.TaskbarProcessor = TaskbarProcessor;
