import { h } from "@stencil/core";
import { PresentationMode } from "../../../lib/@types";
import store from "../../../lib/store";
export 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 = {}));
export var AuthorizationElements;
(function (AuthorizationElements) {
  AuthorizationElements["UPDATE"] = "UPDATE";
  AuthorizationElements["CLONE"] = "CLONE";
  AuthorizationElements["REMOVE"] = "REMOVE";
  AuthorizationElements["INSERT"] = "INSERT";
  AuthorizationElements["CONFIGURATOR"] = "CONFIGURATOR";
})(AuthorizationElements || (AuthorizationElements = {}));
export var VisibleWhenForbidden;
(function (VisibleWhenForbidden) {
  VisibleWhenForbidden["CONFIGURATOR"] = "CONFIGURATOR";
})(VisibleWhenForbidden || (VisibleWhenForbidden = {}));
export 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);
  }
};
export 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;
}
