'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const __chunk_1 = require('./chunk-2755df65.js');

class Tabs {
    constructor(hostRef) {
        __chunk_1.registerInstance(this, hostRef);
    }
    componentDidLoad() {
        this.createGroup().then(() => {
            const [group] = this.tabGroup;
            this.selectGroup(group);
            if (this.selectedIndex)
                this.activeIndex = Number(this.selectedIndex) - 1;
        });
    }
    componentDidUpdate() {
        if (this.selectedIndex)
            this.activeIndex = Number(this.selectedIndex) - 1;
    }
    onSelectedTab(event) {
        const group = this.tabGroup.find(group => group.header.id === event.detail.id);
        this.selectGroup(group);
    }
    async createGroup() {
        const tabsHeaderElements = Array.from(this.host.querySelectorAll('ema-tab-header'));
        this.tabsHeader = [];
        tabsHeaderElements.map(async (el) => {
            this.tabsHeader.push(await el.getChild());
        });
        const tabsContentElements = Array.from(this.host.querySelectorAll('ema-tab-content'));
        this.tabsContent = [];
        tabsContentElements.map(async (el) => {
            this.tabsContent.push(await el.getChild());
        });
        await new Promise(r => setTimeout(r, 40));
        this.tabGroup = this.tabsHeader.map(header => {
            const content = this.tabsContent.find(content => content.name === header.name);
            return {
                header: header,
                content: content
            };
        });
    }
    selectGroup(group) {
        this.tabGroup.forEach(_ => {
            _.header.unselect();
            _.content.unselect();
        });
        group.header.select();
        group.content.select();
    }
    set activeIndex(index) {
        let i = 0;
        this.tabGroup.forEach(_ => {
            if (i == index) {
                _.header.select();
                _.content.select();
            }
            else {
                _.header.unselect();
                _.content.unselect();
            }
            i++;
        });
    }
    render() {
        return [
            __chunk_1.h("div", { class: "ema-tabs-header" }, __chunk_1.h("slot", { name: "header" })),
            __chunk_1.h("div", { class: "ema-tabs-content" }, __chunk_1.h("slot", { name: "content" }))
        ];
    }
    get host() { return __chunk_1.getElement(this); }
    static get style() { return ":root{--ema-color:#343a40;--ema-primary:#007bff;--ema-secondary:#6c757d;--ema-success:#28a745;--ema-info:#17a2b8;--ema-warning:#ffc107;--ema-danger:#dc3545;--ema-light:#f8f9fa;--ema-dark:#343a40;--ema-background:#fff;--ema-background-diap:rgba(29,29,29,0.97);--ema-border-color:#c5c9cd;--ema-border:1px solid #c5c9cd;--ema-border-radius:3px 3px 3px 3px;--ema-box-shadow:1px 1px 10px 1px #ccc;--ema-margin:0.25rem;--ema-margin-sm:0.5rem;--ema-margin-md:1rem;--ema-margin-lg:1.5rem;--ema-margin-xl:2rem;--ema-padding:0.25rem;--ema-padding-sm:0.5rem;--ema-padding-md:1rem;--ema-padding-lg:1.5rem;--ema-padding-xl:2rem;--ema-gray-100:#f8f9fa;--ema-gray-200:#e9ecef;--ema-gray-300:#dee2e6;--ema-gray-400:#ced4da;--ema-gray-500:#adb5bd;--ema-gray-600:#868e96;--ema-gray-700:#495057;--ema-gray-800:#343a40;--ema-gray-900:#212529}.ema-tabs-header{display:-ms-flexbox;display:flex;border-bottom:1px solid rgba(0,0,0,.3)}.ema-tabs-content{padding:10px}"; }
}

exports.ema_tabs = Tabs;
