import { r as registerInstance, h, H as Host, g as getElement } from './index-da72c774.js';
import { c as cls } from './helpers-bcb19b84.js';

const XTab = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.active = undefined;
        this.disabled = undefined;
        this.label = undefined;
        this.icon = undefined;
        this.badge = undefined;
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: 'a68147d278cbcb004db7b1236f97bd12a5a66c9e', class: cls({ 'tab-disabled': this.disabled, 'tab-active': this.active }) }, h("slot", { key: '61f70053a591f5fe3fcc4b4cb2ac01b38e0410b1' }));
    }
    get el() { return getElement(this); }
};

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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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: '9541a54b873833d293506aa08fd11a5f23009f1a' }, h("nav", { key: '7909205527dba262390a1684ce7e109b8ce4b213', class: cls(`tabs-${this.position}`, { 'tabs-block': this.block }) }, h("ul", { key: 'df40c3299330a6df5101cd6bbc00602d3541af84' }, 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: '329fc596f41068dcc51f617d4316936b6b5d0eef', class: "tab-content" }, h("slot", { key: 'c95a1166e98f0bd690f3982ebe662f3e2d65efbe' })));
    }
    get el() { return getElement(this); }
};
XTabs.style = XTabsStyle0;

export { XTab as x_tab, XTabs as x_tabs };
