/*!
 * Crafted with ❤ by Salla
 */
import { r as registerInstance, h, c as createEvent, a as getElement } from './index-Cb4NFvMH.js';

const sallaTabContentCss = "";

const SallaTabContent = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.isSelected = false;
    }
    /**
     * Expose self for the parent.
     */
    async getChild() {
        return {
            selected: this.selected.bind(this),
            unselect: this.unselect.bind(this),
            name: this.name
        };
    }
    unselect() {
        this.isSelected = false;
    }
    selected() {
        this.isSelected = true;
    }
    render() {
        const classes = {
            's-tabs-content': true,
            's-tabs-content-selected': this.isSelected
        };
        return (h("div", { key: '8678e860af6640f0ff1a92593fbe624416412b49', class: classes }, h("slot", { key: '10951e5230f9c5fbfbd5959d3773d44b66e85315' })));
    }
};
SallaTabContent.style = sallaTabContentCss;

function generateRandomId() {
    return Math.random().toString(36).slice(2, 10);
}

const sallaTabHeaderCss = "";

const SallaTabHeader = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.tabSelected = createEvent(this, "tabSelected");
        this.id = generateRandomId();
        /**
       * The class applied to the currently active(selected) tab
       */
        this.activeClass = undefined;
        /**
         * Set the height of the tab bar
         */
        this.height = undefined;
        /**
         * Center tab items in the given flex.
         */
        this.centered = false;
        this.isSelected = false;
    }
    /**
     * Expose self for the parent.
     */
    async getChild() {
        return {
            selected: this.selected.bind(this),
            unselect: this.unselect.bind(this),
            name: this.name,
            id: this.id
        };
    }
    unselect() {
        this.isSelected = false;
    }
    selected() {
        this.isSelected = true;
    }
    onClick() {
        this.getChild().then(child => {
            this.tabSelected.emit(child);
        });
    }
    render() {
        const classes = {
            's-tabs-header-item': true,
            's-tabs-bg-normal': true,
            's-tabs-active': this.isSelected,
        };
        return [
            h("div", { key: '02bd540222ec3bd4adac0dd08132c366e29c6d9d', class: classes, onClick: this.onClick.bind(this) }, h("slot", { key: '9e6de884cb209d499e4bbd055e40c525680a7c37' })),
        ];
    }
};
SallaTabHeader.style = sallaTabHeaderCss;

const sallaTabsCss = ".s-tabs-header{-ms-overflow-style:none;scrollbar-width:none;}.s-tabs-header::-webkit-scrollbar{display:none}";

const SallaTabs = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /**
         * Background color
         */
        this.backgroundColor = undefined;
        /**
         * Align tabs vertically.
         */
        this.vertical = false;
    }
    componentWillLoad() {
        this.createGroup().then(() => {
            const [group] = this.tabGroup;
            this.selectGroup(group);
        });
    }
    onSelectedTab(event) {
        const group = this.tabGroup.find(group => group.header.id === event.detail.id);
        this.selectGroup(group);
    }
    async createGroup() {
        const tabsHeaderEl = Array.from(this.host.querySelectorAll('salla-tab-header'));
        this.tabsHeader = await Promise.all(tabsHeaderEl.map(async (el) => await el.getChild()));
        const tabsContentEl = Array.from(this.host.querySelectorAll('salla-tab-content'));
        this.tabsContent = await Promise.all(tabsContentEl.map(async (el) => await el.getChild()));
        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.map(g => {
            g.header.unselect();
            g.content.unselect();
        });
        group.header.selected();
        group.content.selected();
    }
    render() {
        return [
            h("div", { key: 'ecbcdc11af92d35afe933b11676bcf4769d19162', class: "s-tabs" }, h("div", { key: 'fa4fdecbc995dded92e3d64bf770d6375ad53fd2', class: "s-tabs-header" }, h("slot", { key: '730c1a278e95b7fa98da29956fee23dcd06e641d', name: "header" })), h("div", { key: '9721096ba8e1236500855a80f569e6ea8a4c1c32', class: "s-tabs-content-wrapper" }, h("slot", { key: 'ce82c43fd21bd1f28a7658b927646d0ff6052ea7', name: "content" })))
        ];
    }
    get host() { return getElement(this); }
};
SallaTabs.style = sallaTabsCss;

export { SallaTabContent as salla_tab_content, SallaTabHeader as salla_tab_header, SallaTabs as salla_tabs };
