import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';

const taskbarSplitButtonCss = "";

const TaskbarSplitButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this._showDropdown = false;
    this.iconName = undefined;
    this.action = undefined;
    this.name = undefined;
    this.className = undefined;
    this.dataElementId = undefined;
    this.title = undefined;
    this.enabled = undefined;
    this.actions = undefined;
  }
  initializeEagerItems() {
    var _a;
    (_a = this.actions) === null || _a === void 0 ? void 0 : _a.forEach(action => {
      var _a;
      if (action && action.eagerInitialize && action.itemBuilder) {
        (_a = action.itemBuilder) === null || _a === void 0 ? void 0 : _a.call(action, this._splitButtonRef, action);
      }
    });
  }
  componentDidLoad() {
    this.initializeEagerItems();
  }
  dropdownItemBuilder(item, _level) {
    const itemAction = this.actions.find(action => action.value === item.id);
    if (!itemAction || !itemAction.itemBuilder) {
      return undefined;
    }
    const customContent = itemAction.itemBuilder(this._splitButtonRef, itemAction);
    if (typeof customContent === 'string') {
      return h("div", { innerHTML: customContent });
    }
    return customContent;
  }
  loadItems() {
    return this.actions.filter(action => action !== undefined).map(action => {
      var _a;
      return {
        id: action.value,
        label: action.label,
        value: action.value,
        type: (_a = action.type) !== null && _a !== void 0 ? _a : 'item',
        children: action.children,
        iconName: action.iconName,
        subAction: action.subAction,
        group: action.group,
        disableCloseOnSelect: action.disableCloseOnSelect,
      };
    });
  }
  render() {
    return (h(Host, null, h("ez-split-button", { ref: (ref) => this._splitButtonRef = ref, key: this.dataElementId, class: `${this.className} "ez-split-button--tertiary ez-padding--medium"`, items: this.loadItems(), mode: "icon-only", iconName: this.iconName, enabled: this.enabled, show: this._showDropdown, onButtonClick: () => this.action(this.name), itemBuilder: (item, level) => this.dropdownItemBuilder(item, level) })));
  }
  static get style() { return taskbarSplitButtonCss; }
}, [2, "taskbar-split-button", {
    "iconName": [1, "icon-name"],
    "action": [16],
    "name": [1],
    "className": [1, "class-name"],
    "dataElementId": [1, "data-element-id"],
    "title": [1],
    "enabled": [4],
    "actions": [16],
    "_showDropdown": [32]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["taskbar-split-button"];
  components.forEach(tagName => { switch (tagName) {
    case "taskbar-split-button":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, TaskbarSplitButton);
      }
      break;
  } });
}

export { TaskbarSplitButton as T, defineCustomElement as d };
