import { h, Host } from '@stencil/core';
export class TaskbarSplitButton {
  constructor() {
    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 is() { return "taskbar-split-button"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() {
    return {
      "$": ["taskbar-split-button.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["taskbar-split-button.css"]
    };
  }
  static get properties() {
    return {
      "iconName": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Nome do \u00EDcone a ser exibido no bot\u00E3o."
        },
        "attribute": "icon-name",
        "reflect": false
      },
      "action": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "(name: string) => void",
          "resolved": "(name: string) => void",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "param",
              "text": "name Nome da a\u00E7\u00E3o a ser executada."
            }],
          "text": "Fun\u00E7\u00E3o de callback acionada ao clicar no bot\u00E3o principal."
        }
      },
      "name": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Nome identificador da a\u00E7\u00E3o do bot\u00E3o."
        },
        "attribute": "name",
        "reflect": false
      },
      "className": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Classe CSS personalizada para estilizar o bot\u00E3o."
        },
        "attribute": "class-name",
        "reflect": false
      },
      "dataElementId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Identificador de elemento para fins de rastreamento e automa\u00E7\u00E3o de testes."
        },
        "attribute": "data-element-id",
        "reflect": false
      },
      "title": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Texto que ser\u00E1 exibido no bot\u00E3o."
        },
        "attribute": "title",
        "reflect": false
      },
      "enabled": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Se false o usu\u00E1rio n\u00E3o pode interagir com o componente."
        },
        "attribute": "enabled",
        "reflect": false
      },
      "actions": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "Array<Action>",
          "resolved": "Action[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "Action": {
              "location": "import",
              "path": "../../snk-taskbar"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Define a lista de a\u00E7\u00F5es dispon\u00EDveis no dropdown do bot\u00E3o."
        }
      }
    };
  }
  static get states() {
    return {
      "_showDropdown": {}
    };
  }
}
