import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { c as cls } from './helpers.js';
import { d as defineCustomElement$2 } from './component5.js';
import { d as defineCustomElement$1 } from './component.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, #d8d8d8);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[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-fluid ul{padding-left:1.2rem;padding-right:1.2rem;border-bottom-color:rgba(var(--color-border-rgb, 200, 199, 204), 0.35)}x-tabs .tabs-fluid ul li a{border-bottom-color:transparent}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 = /*@__PURE__*/ proxyCustomElement(class XTabs extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.fluid = undefined;
        this.block = false;
        this.position = 'left';
        this.tabs = [];
    }
    /**
     * Element event on slot make changes
     *
     * @param evt
     */
    handleSlotChange() {
        this.computeChildTabs();
    }
    /**
     * On component will loaded hook
     */
    componentWillLoad() {
        this.computeChildTabs();
    }
    /**
     * On component did loaded hook
     */
    componentDidLoad() {
        if (!this.tabs.length) {
            return;
        }
        setTimeout(() => {
            const validTabs = this.tabs.filter(tab => !tab.disabled);
            const activeTabs = validTabs.filter(tab => tab.active);
            if (!activeTabs.length) {
                this.showTab(validTabs[0]);
            }
        }, 0);
    }
    /**
     * Update the child tabs and render the result
     */
    computeChildTabs() {
        this.tabs = Array.from(this.el.children)
            .filter(tab => tab.nodeName.toLowerCase() === 'x-tab')
            .map(el => el);
        this.tabs.forEach((tab, index) => {
            tab.index = index;
        });
    }
    /**
     * Show the content of selected tab by index and set active
     *
     * @param index
     * @param tab
     */
    showTab(tab) {
        this.tabs.filter(tab => tab.active).forEach(tab => {
            tab.active = false;
        });
        this.el.querySelectorAll('nav li.tab-active').forEach(li => li.classList.remove('tab-active'));
        setTimeout(() => {
            var _a;
            tab && (tab.active = true);
            (_a = this.el.querySelector(`.tab-index-${tab.index}`)) === null || _a === void 0 ? void 0 : _a.classList.add('tab-active');
        }, 0);
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: '7cf0f4d63c50b7b6f2f6616d9a6a7d8300059a26' }, h("nav", { key: '5b5cd7ead3928070a34d833f0fe95ce41bc609c4', class: cls(`tabs-${this.position}`, { 'tabs-block': this.block, 'tabs-fluid': this.fluid }) }, h("ul", { key: '08d9f4977059fec57e214af9ec4b5125101c7e71' }, this.tabs.map((tab, i) => h("li", { key: i, class: cls(`tab-index-${i}`, { 'tab-disabled': tab.disabled, 'tab-active': tab.active }) }, h("a", { href: "javascript:;", tabIndex: i, onClick: () => this.showTab(tab) }, tab.icon && h("x-icon", { name: tab.icon }), h("span", null, tab.label), tab.badge && h("x-badge", { color: "primary" }, tab.badge)))))), h("div", { key: 'eff80d271876d537625ec4f32ac5c741b4229794', class: "tab-content" }, h("slot", { key: 'fa3d3a705d01254993acd1d0a25770e6d7004c75' })));
    }
    get el() { return this; }
    static get style() { return XTabsStyle0; }
}, [4, "x-tabs", {
        "fluid": [4],
        "block": [4],
        "position": [1],
        "tabs": [32]
    }, [[0, "slotchange", "handleSlotChange"]]]);
function defineCustomElement() {
    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);
            }
            break;
        case "x-badge":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "x-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { XTabs as X, defineCustomElement as d };
