import { h, Host } from '@stencil/core';
/**
 * Tab component, must be a child of `bs-tab-list`.  See `bs-tab-list` for more information.
 * Consumers MUST set an `id` attribute to associate each tab with its corresponding panel.
 * The tab's panel must have an id matching the pattern "[this-tab-id]-panel" unless the `panelId` prop is passed.
 * @docsPage
 */
export class BsTab {
  constructor() {
    this.activeTabId = undefined;
    this.hidden = false;
    this.panelId = undefined;
  }
  get isActive() {
    return this.activeTabId && this.activeTabId === this.hostEl.id;
  }
  get panelIdComputed() {
    return this.panelId || `${this.hostEl.id}-panel`;
  }
  validSiblingOrNull(el) {
    var _a, _b;
    return (((_a = el === null || el === void 0 ? void 0 : el.dataset) === null || _a === void 0 ? void 0 : _a.hidden) === '' || ((_b = el === null || el === void 0 ? void 0 : el.dataset) === null || _b === void 0 ? void 0 : _b.hidden) === 'true') ? null : el;
  }
  // avoid unnecessary re-renders
  componentShouldUpdate(newValue, oldValue, propName) {
    if (newValue === oldValue)
      return false;
    if (propName === 'activeTabId') {
      return newValue === this.hostEl.id || oldValue === this.hostEl.id;
    }
  }
  handleKeydown(e) {
    if (e.key === 'Enter' || e.key === ' ') {
      e.preventDefault();
      e.stopPropagation();
      this.hostEl.click();
    }
  }
  render() {
    return (h(Host, { "aria-controls": this.panelIdComputed, "aria-selected": this.isActive ? "true" : "false", "data-hidden": this.hidden || undefined, role: "tab", tabindex: "0" }, h("slot", null)));
  }
  static get is() { return "bs-tab"; }
  static get properties() {
    return {
      "activeTabId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "The id of the currently selected tab button."
        },
        "attribute": "active-tab-id",
        "reflect": false
      },
      "hidden": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Whether or not this tab is hidden."
        },
        "attribute": "hidden",
        "reflect": false,
        "defaultValue": "false"
      },
      "panelId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "The id of the tab panel associated with this tab.\nIf undefined, this tab will assume the panel id matches pattern \"[this-tab-id]-panel\""
        },
        "attribute": "panel-id",
        "reflect": false
      }
    };
  }
  static get elementRef() { return "hostEl"; }
  static get listeners() {
    return [{
        "name": "keydown",
        "method": "handleKeydown",
        "target": undefined,
        "capture": false,
        "passive": false
      }];
  }
}
//# sourceMappingURL=bs-tab.js.map
