import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { c as cls } from './helpers.js';
import { d as defineCustomElement$3 } from './component3.js';
import { d as defineCustomElement$2 } from './component2.js';

const styleCss = "x-tabs>nav{font-family:inherit;-ms-flex-align:center;align-items:center;display:-ms-flexbox !important;display:flex !important;-ms-flex-positive:1;flex-grow:1;-ms-flex-negative:0;flex-shrink:0;-ms-flex-pack:start;justify-content:flex-start;overflow-y:auto;-ms-overflow-style:none;scrollbar-width:none}x-tabs>nav::-webkit-scrollbar{display:none}x-tabs>nav ul{-ms-flex-align:center;align-items:center;border-bottom-color:var(--color-default-lucid, #f0f0f0);border-bottom-style:solid;border-bottom-width:2px;display:-ms-flexbox;display:flex;-ms-flex-positive:1;flex-grow:1;-ms-flex-negative:0;flex-shrink:0;-ms-flex-pack:start;justify-content:flex-start;padding-left:0px;padding-top:0px;margin-top:0px;margin-bottom:0px}.is-dark-mode x-tabs>nav ul{border-bottom-color:var(--color-default-shadest, #464646)}x-tabs>nav li{list-style:none;cursor:pointer}x-tabs>nav li a{-ms-flex-align:center;align-items:center;border-bottom-color:var(--color-default-lucid, #f0f0f0);border-bottom-style:solid;border-bottom-width:2px;color:var(--color-text, #4A4A4A);display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;padding:0.5em 1em;vertical-align:top;margin-bottom:-2px;min-height:28px}.is-dark-mode x-tabs>nav li a{color:var(--color-text-light-shade);border-bottom-color:var(--color-default-shadest, #464646)}x-tabs>nav li a>x-icon{font-size:1.5rem;margin-right:5px}x-tabs>nav li a x-badge{margin-left:0.5rem}x-tabs>nav li.tab-disabled{pointer-events:none;cursor:not-allowed;opacity:0.5}x-tabs>nav .is-transitioning{overflow:hidden}x-tabs li.tab-active a{border-bottom-color:var(--color-primary, #4275F2) !important;color:var(--color-primary, #4275F2);font-weight:bolder}.is-dark-mode x-tabs li.tab-active a{color:var(--color-primary, #4275F2)}x-tabs li.tab-active a:hover{color:var(--color-primary-shade, #3863ce)}x-tabs .tab-content{position:relative;overflow:visible;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;padding:1rem}.is-dark-mode x-tabs .tab-content{color:var(--color-text-light, #FEFEFE)}x-tabs .tab-content x-tab{-ms-flex-negative:0;flex-shrink:0;-ms-flex-preferred-size:auto;flex-basis:auto;display:none}x-tabs .tab-content x-tab.tab-active{display:block;-webkit-animation:tabShow 0.4s;animation:tabShow 0.4s}x-tabs .tab-content.is-transitioning{overflow:hidden}x-tabs .tabs-block{width:100%}x-tabs .tabs-block ul{-ms-flex-pack:distribute;justify-content:space-around}x-tabs .tabs-block li{width:100%}x-tabs .tabs-left ul{-ms-flex-pack:start;justify-content:flex-start}x-tabs .tabs-centered ul{-ms-flex-pack:center;justify-content:center}x-tabs .tabs-right ul{-ms-flex-pack:end;justify-content:flex-end}@-webkit-keyframes tabShow{from{opacity:0;-webkit-transform:translate3d(-1rem, 0, 0);transform:translate3d(-1rem, 0, 0)}to{opacity:1;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}}@keyframes tabShow{from{opacity:0;-webkit-transform:translate3d(-1rem, 0, 0);transform:translate3d(-1rem, 0, 0)}to{opacity:1;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}}";
const XTabsStyle0 = styleCss;

const XTabs$1 = /*@__PURE__*/ proxyCustomElement(class XTabs extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.block = false;
        this.position = 'left';
        this.tabs = [];
    }
    /**
     * Element event on slot make changes
     *
     * @param evt
     */
    handleSlotChange() {
        this.computeChildTabs();
    }
    /**
     * On component did loaded hook
     */
    componentDidLoad() {
        this.computeChildTabs();
        if (!this.tabs.length) {
            return;
        }
        setTimeout(() => {
            if (!this.el.querySelectorAll('nav .tab-active').length) {
                this.showTab(0, this.el.querySelectorAll('.tab-content x-tab').item(0));
            }
        }, 10);
    }
    /**
     * Update the child tabs and render teh result
     */
    computeChildTabs() {
        this.tabs = Array.from(this.el.querySelector('.tab-content').children)
            .filter(tab => tab.nodeName.toLowerCase() === 'x-tab');
    }
    /**
     * Show the content of selected tab by index and set active
     *
     * @param index
     * @param tab
     */
    showTab(index, tab) {
        this.el.querySelectorAll('x-tab.tab-active, nav li.tab-active').forEach(tab => {
            tab.setAttribute('active', 'false');
            tab.classList.remove('tab-active');
        });
        setTimeout(() => {
            var _a;
            (_a = this.el.querySelector(`.tab-index-${index}`)) === null || _a === void 0 ? void 0 : _a.classList.add('tab-active');
            tab.setAttribute('active', 'true');
        }, 10);
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: '8616c2a0e498a85c2666833168b966190902ab3a' }, h("nav", { key: '4e7b30cc0c37f16fc6b0a774502f3438d91d8942', class: cls(`tabs-${this.position}`, { 'tabs-block': this.block }) }, h("ul", { key: 'bf8cbfd4ab63740ebc6aa29d5c549d4db1629b52' }, this.tabs.map((tab, i) => (h("li", { key: i, class: cls(`tab-index-${i}`, { 'tab-disabled': tab.classList.contains('tab-disabled'), 'tab-active': tab.classList.contains('tab-active') }) }, h("a", { href: "javascript:;", tabIndex: i, onClick: () => this.showTab(i, tab) }, tab.getAttribute('icon') && h("x-icon", { name: tab.getAttribute('icon') }), h("span", null, tab.getAttribute('label')), tab.getAttribute('badge') && h("x-badge", { color: "primary" }, tab.getAttribute('badge')))))))), h("div", { key: '9a401c184e86576797d34dcd57fc9605d88bb5f4', class: "tab-content" }, h("slot", { key: 'f9cb7c5a3e01ea30aeff1e236e2e9614b64f4957' })));
    }
    get el() { return this; }
    static get style() { return XTabsStyle0; }
}, [4, "x-tabs", {
        "block": [4],
        "position": [1],
        "tabs": [32]
    }, [[0, "slotchange", "handleSlotChange"]]]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-tabs", "x-badge", "x-icon"];
    components.forEach(tagName => { switch (tagName) {
        case "x-tabs":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XTabs$1);
            }
            break;
        case "x-badge":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "x-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const XTabs = XTabs$1;
const defineCustomElement = defineCustomElement$1;

export { XTabs, defineCustomElement };
