import { r as registerInstance, h, H as Host, g as getElement } from './index-4a3a9179.js';

const pdsTabsCss = ":host{--panel-margin-top:0;--panel-padding:0;--gap-md:var(--pine-spacing-md);--gap-xs:var(--pine-spacing-xs);--gap-sm:16px var(--pine-spacing-sm);--outline:2px solid var(--pine-color-primary-200);display:block}*:focus{outline:var(--outline)}.pds-tabs__tablist{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:var(--gap-md)}:host(.pds-tabs--availability) .pds-tabs__tablist{gap:var(--gap-xs)}:host(.pds-tabs--filter) .pds-tabs__tablist{gap:var(--gap-sm)}";
const PdsTabsStyle0 = pdsTabsCss;

const PdsTabs = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.tablistLabel = undefined;
        this.componentId = undefined;
        this.variant = undefined;
        this.activeTabName = undefined;
        this.activeTabIndex = undefined;
    }
    tabClickHandler(event) {
        if (this.componentId === event.detail[1]) {
            this.activeTabIndex = event.detail[0];
            this.activeTabName = this.tabs[this.activeTabIndex].name;
        }
    }
    handleKeyDown(ev) {
        const keySet = ["ArrowLeft", "ArrowRight", "Home", "End"];
        if (keySet.includes(ev.key)) {
            ev.preventDefault();
            this.moveActiveTab(ev.key);
        }
    }
    moveActiveTab(key) {
        const firstTabNumber = 0;
        const lastTabNumber = this.tabs.length - 1;
        let moveFocusTo = null;
        switch (key) {
            case 'ArrowLeft':
                moveFocusTo = (this.activeTabIndex === firstTabNumber) ? lastTabNumber : (this.activeTabIndex + (-1));
                break;
            case 'ArrowRight':
                moveFocusTo = (this.activeTabIndex === lastTabNumber) ? firstTabNumber : (this.activeTabIndex + 1);
                break;
            case 'Home':
                moveFocusTo = firstTabNumber;
                break;
            case 'End':
                moveFocusTo = lastTabNumber;
                break;
        }
        // Move focus to the button element within `pds-tab`
        this.tabs[moveFocusTo].children[0].focus();
        this.activeTabName = this.tabs[moveFocusTo].name;
        this.activeTabIndex = moveFocusTo;
    }
    findAllChildren() {
        this.tabs = this.el.querySelectorAll('pds-tab');
        this.tabPanels = this.el.querySelectorAll('pds-tabpanel');
    }
    propGeneration(child, index = 0) {
        child.parentComponentId = this.componentId.toString();
        child.variant = this.variant.toString();
        child.selected = (this.activeTabName === child.name) ? true : false;
        child['index'] = index;
    }
    passPropsToChildren() {
        this.tabs.forEach((child, index) => {
            if (this.activeTabName === child.name)
                this.activeTabIndex = index;
            this.propGeneration(child, index);
        });
        this.tabPanels.forEach((child) => {
            this.propGeneration(child);
        });
    }
    classNames() {
        let className = `pds-tabs`;
        if (this.variant && this.variant != 'primary') {
            const variantClassName = `pds-tabs--${this.variant}`;
            className += ' ' + variantClassName;
        }
        return className;
    }
    ;
    componentWillLoad() {
        this.findAllChildren();
    }
    componentWillRender() {
        this.passPropsToChildren();
    }
    render() {
        return (h(Host, { key: '230c4abd9bf8632802f34df2a517ca2c1cc029bd', "active-tab-name": this.activeTabName, class: this.classNames(), id: this.componentId }, h("div", { key: 'ad7935e2494c8fa731abaf17979f61ffa70d8ac3', class: "pds-tabs__tablist", role: "tablist", "aria-label": this.tablistLabel }, h("slot", { key: '3e3b604d8aa3391b23539914cd91bd6cafcfc4c9', name: "tabs" })), h("slot", { key: '7d8a5ee7b1b147816bedf6be0b24f8a57b422fe7', name: "tabpanels" })));
    }
    get el() { return getElement(this); }
};
PdsTabs.style = PdsTabsStyle0;

export { PdsTabs as pds_tabs };

//# sourceMappingURL=pds-tabs.entry.js.map