import { Component, Host, h, Element, State, Event, Method, Prop } from '@stencil/core';
export class Tabs {
  constructor() {
    this.tabsOptions = [];
    /**
     * Defines the layout of the tabs.
     */
    this.interface = 'tabs';
    /**
     * If `true` the field expands over the whole width.
     */
    this.expanded = false;
    /**
     * If `true` the padding gets reduced.
     */
    this.dense = false;
    /**
     * If you want the rounded tab style.
     */
    this.rounded = false;
    /**
     * If `true` a acation button is added to the right
     */
    this.action = false;
    /**
     * Label for the action button
     */
    this.actionLabel = '';
  }
  /**
   * Go to tab with the given value
   */
  async select(tab) {
    this.tabs.forEach(t => t.setActive(t.value === tab.value));
    this.sync();
    this.tabsDidChange.emit(tab);
  }
  /**
   * *Internal* Rerenders the tabs with their given settings
   */
  async sync() {
    Promise.all(this.tabs.map(value => value.getOptions())).then(tabsOptions => {
      this.tabsOptions = tabsOptions;
    });
  }
  componentWillLoad() {
    this.sync();
  }
  get tabs() {
    return Array.from(this.element.querySelectorAll('bal-tab-item'));
  }
  async onSelectTab(tab) {
    if (!tab.disabled) {
      await this.select(tab);
      this.tabsDidChange.emit(tab);
    }
  }
  render() {
    if (this.interface === 'steps') {
      return this.renderSteps();
    }
    else {
      return this.renderTabs();
    }
  }
  renderSteps() {
    return (h(Host, { class: "bal-steps" },
      h("div", { class: ['tabs is-fullwidth'].join(' ') },
        h("ul", null, this.tabsOptions.map((tab, index) => (h("li", { class: {
            'is-active': tab.active,
            'is-disabled': tab.disabled,
            'is-done': tab.done,
            'is-failed': tab.failed,
          } },
          h("a", { onClick: () => this.onSelectTab(tab) },
            h("span", { class: "step-index" },
              h("span", null, index + 1)),
            h("span", { class: "step-label" }, tab.label)),
          h("span", { class: "bubble", style: !tab.hasBubble && { display: 'none' } })))))),
      h("slot", null)));
  }
  renderTabs() {
    return (h(Host, { class: "bal-tabs" },
      h("div", { class: [
          'tabs',
          this.rounded ? 'is-rounded' : '',
          this.dense ? 'is-dense' : '',
          this.expanded ? 'is-fullwidth' : '',
        ].join(' ') },
        h("ul", null,
          this.tabsOptions.map(tab => (h("li", { class: [tab.active ? 'is-active' : '', tab.disabled ? 'is-disabled' : ''].join(' ') },
            h("a", { onClick: () => this.onSelectTab(tab) }, tab.label),
            h("span", { class: "bubble", style: !tab.hasBubble && { display: 'none' } })))),
          h("li", { class: "is-right", style: { display: this.action ? 'block' : 'none' } },
            h("bal-button", { onClick: e => this.actionHasClicked.emit(e) }, this.actionLabel)))),
      h("slot", null)));
  }
  static get is() { return "bal-tabs"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["bal-tabs.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["bal-tabs.css"]
  }; }
  static get properties() { return {
    "interface": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'tabs' | 'steps'",
        "resolved": "\"steps\" | \"tabs\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Defines the layout of the tabs."
      },
      "attribute": "interface",
      "reflect": false,
      "defaultValue": "'tabs'"
    },
    "expanded": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` the field expands over the whole width."
      },
      "attribute": "expanded",
      "reflect": false,
      "defaultValue": "false"
    },
    "dense": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` the padding gets reduced."
      },
      "attribute": "dense",
      "reflect": false,
      "defaultValue": "false"
    },
    "rounded": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If you want the rounded tab style."
      },
      "attribute": "rounded",
      "reflect": false,
      "defaultValue": "false"
    },
    "action": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` a acation button is added to the right"
      },
      "attribute": "action",
      "reflect": false,
      "defaultValue": "false"
    },
    "actionLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Label for the action button"
      },
      "attribute": "action-label",
      "reflect": false,
      "defaultValue": "''"
    }
  }; }
  static get states() { return {
    "tabsOptions": {}
  }; }
  static get events() { return [{
      "method": "tabsDidChange",
      "name": "balTabChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Emitted when the changes has finished."
      },
      "complexType": {
        "original": "BalTabOption",
        "resolved": "BalTabOption",
        "references": {
          "BalTabOption": {
            "location": "import",
            "path": "./bal-tab.type"
          }
        }
      }
    }, {
      "method": "actionHasClicked",
      "name": "balActionClick",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Emitted when the action button has clicked"
      },
      "complexType": {
        "original": "MouseEvent",
        "resolved": "MouseEvent",
        "references": {
          "MouseEvent": {
            "location": "global"
          }
        }
      }
    }]; }
  static get methods() { return {
    "select": {
      "complexType": {
        "signature": "(tab: BalTabOption) => Promise<void>",
        "parameters": [{
            "tags": [],
            "text": ""
          }],
        "references": {
          "Promise": {
            "location": "global"
          },
          "BalTabOption": {
            "location": "import",
            "path": "./bal-tab.type"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Go to tab with the given value",
        "tags": []
      }
    },
    "sync": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "*Internal* Rerenders the tabs with their given settings",
        "tags": []
      }
    }
  }; }
  static get elementRef() { return "element"; }
}
