/*!
 * (C) Ionic http://ionicframework.com - MIT License
 */
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { c as createKeyboardController } from './keyboard-controller.js';
import { c as createColorClasses } from './theme.js';
import { b as getIonTheme } from './ionic-global.js';

const tabBarIonicCss = ":host{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-top:var(--border);background:var(--background);color:var(--color);text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-box-sizing:content-box !important;box-sizing:content-box !important}:host(.ion-color) ::slotted(ion-tab-button.ion-focused),:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:var(--background-focused)}:host(.tab-bar-translucent) ::slotted(ion-tab-button){background:transparent}:host([slot=top]){border-top:0;border-bottom:var(--border)}:host(.tab-bar-hidden){display:none !important}:host(.tab-bar-full){width:auto;contain:strict;padding-bottom:var(--ion-safe-area-bottom, 0);padding-right:var(--ion-safe-area-right);padding-left:var(--ion-safe-area-left);}:host([slot=top].tab-bar-full){padding-top:var(--ion-safe-area-top, 0);padding-bottom:0}:host{--background:var(--ion-tab-bar-background, var(--token-bg-surface-default, var(--token-primitives-base-white, #ffffff)));--background-activated:var(--ion-tab-bar-background-activated, var(--token-bg-select-default, var(--token-semantics-primary-100, var(--token-primitives-blue-100, #e9ecfc))));--background-focused:var(--ion-tab-bar-background-focused, transparent);--border:var(--token-border-size-0, var(--token-scale-0, 0px)) var(--token-border-style-solid, solid) var(--ion-tab-bar-border-color, transparent);--color:var(--ion-tab-bar-color, var(--token-primitives-neutral-800, #626262));--color-selected:var(--ion-tab-bar-color-selected, var(--token-text-primary, var(--token-semantics-primary-900, var(--token-primitives-blue-900, #0d4bc3))));-ms-flex-pack:unset;justify-content:unset;max-width:100%;min-height:calc(var(--token-scale-1400, 56px) - var(--token-space-100, var(--token-scale-100, 4px)) * 2);gap:var(--token-space-300, var(--token-scale-300, 12px));-webkit-box-shadow:var(--token-elevation-2, 0px 1px 5px 0px rgba(0, 0, 0, 0.05), 0px 8px 25px 0px rgba(0, 0, 0, 0.08));box-shadow:var(--token-elevation-2, 0px 1px 5px 0px rgba(0, 0, 0, 0.05), 0px 8px 25px 0px rgba(0, 0, 0, 0.08));overflow:auto hidden;z-index:10}:host(.tab-bar-full){padding-top:var(--token-space-100, var(--token-scale-100, 4px));padding-bottom:calc(var(--token-space-100, var(--token-scale-100, 4px)) + var(--ion-safe-area-bottom, 0));padding-right:calc(var(--token-space-400, var(--token-scale-400, 16px)) + var(--ion-safe-area-right, 0));padding-left:calc(var(--token-space-400, var(--token-scale-400, 16px)) + var(--ion-safe-area-left, 0));}:host([slot=top].tab-bar-full){padding-top:calc(var(--token-space-100, var(--token-scale-100, 4px)) + var(--ion-safe-area-top, 0));padding-bottom:var(--token-space-100, var(--token-scale-100, 4px))}:host(.tab-bar-compact){-webkit-padding-start:var(--token-space-400, var(--token-scale-400, 16px));padding-inline-start:var(--token-space-400, var(--token-scale-400, 16px));-webkit-padding-end:var(--token-space-400, var(--token-scale-400, 16px));padding-inline-end:var(--token-space-400, var(--token-scale-400, 16px));padding-top:var(--token-space-100, var(--token-scale-100, 4px));padding-bottom:var(--token-space-100, var(--token-scale-100, 4px));position:absolute;-ms-flex-item-align:center;align-self:center;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;contain:content}:host([slot=top].tab-bar-compact){top:calc(var(--token-space-100, var(--token-scale-100, 4px)) + var(--ion-safe-area-top, 0))}:host([slot=bottom].tab-bar-compact){bottom:calc(var(--token-space-400, var(--token-scale-400, 16px)) + var(--ion-safe-area-bottom, 0))}:host(.tab-bar-soft){border-radius:var(--token-border-radius-400, var(--token-scale-400, 16px))}:host(.tab-bar-round){border-radius:var(--token-border-radius-full, 999px)}:host(.tab-bar-rectangular){border-radius:var(--token-border-radius-0, var(--token-scale-0, 0px))}";

const tabBarIosCss = ":host{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-top:var(--border);background:var(--background);color:var(--color);text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-box-sizing:content-box !important;box-sizing:content-box !important}:host(.ion-color) ::slotted(ion-tab-button.ion-focused),:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:var(--background-focused)}:host(.tab-bar-translucent) ::slotted(ion-tab-button){background:transparent}:host([slot=top]){border-top:0;border-bottom:var(--border)}:host(.tab-bar-hidden){display:none !important}:host(.tab-bar-full){width:auto;contain:strict;padding-bottom:var(--ion-safe-area-bottom, 0);padding-right:var(--ion-safe-area-right);padding-left:var(--ion-safe-area-left);}:host([slot=top].tab-bar-full){padding-top:var(--ion-safe-area-top, 0);padding-bottom:0}:host{z-index:10}:host(.ion-color) ::slotted(ion-tab-button){--background-focused:var(--ion-color-shade);--color-selected:var(--ion-color-contrast)}:host(.ion-color) ::slotted(.tab-selected){color:var(--ion-color-contrast)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){color:rgba(var(--ion-color-contrast-rgb), 0.7)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){background:var(--ion-color-base)}:host{--background:var(--ion-tab-bar-background, var(--ion-color-step-50, var(--ion-background-color-step-50, #f7f7f7)));--background-focused:var(--ion-tab-bar-background-focused, #e0e0e0);--border:0.55px solid var(--ion-tab-bar-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.2)))));--color:var(--ion-tab-bar-color, var(--ion-color-step-600, var(--ion-text-color-step-400, #666666)));--color-selected:var(--ion-tab-bar-color-selected, var(--ion-color-primary, #0054e9));height:50px}@supports ((-webkit-backdrop-filter: blur(0)) or (backdrop-filter: blur(0))){:host(.tab-bar-translucent){--background:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8);-webkit-backdrop-filter:saturate(210%) blur(20px);backdrop-filter:saturate(210%) blur(20px)}:host(.ion-color.tab-bar-translucent){background:rgba(var(--ion-color-base-rgb), 0.8)}:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.6)}}";

const tabBarMdCss = ":host{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-top:var(--border);background:var(--background);color:var(--color);text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-box-sizing:content-box !important;box-sizing:content-box !important}:host(.ion-color) ::slotted(ion-tab-button.ion-focused),:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:var(--background-focused)}:host(.tab-bar-translucent) ::slotted(ion-tab-button){background:transparent}:host([slot=top]){border-top:0;border-bottom:var(--border)}:host(.tab-bar-hidden){display:none !important}:host(.tab-bar-full){width:auto;contain:strict;padding-bottom:var(--ion-safe-area-bottom, 0);padding-right:var(--ion-safe-area-right);padding-left:var(--ion-safe-area-left);}:host([slot=top].tab-bar-full){padding-top:var(--ion-safe-area-top, 0);padding-bottom:0}:host{z-index:10}:host(.ion-color) ::slotted(ion-tab-button){--background-focused:var(--ion-color-shade);--color-selected:var(--ion-color-contrast)}:host(.ion-color) ::slotted(.tab-selected){color:var(--ion-color-contrast)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){color:rgba(var(--ion-color-contrast-rgb), 0.7)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){background:var(--ion-color-base)}:host{--background:var(--ion-tab-bar-background, var(--ion-background-color, #fff));--background-focused:var(--ion-tab-bar-background-focused, #e0e0e0);--border:1px solid var(--ion-tab-bar-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.07)))));--color:var(--ion-tab-bar-color, var(--ion-color-step-650, var(--ion-text-color-step-350, #595959)));--color-selected:var(--ion-tab-bar-color-selected, var(--ion-color-primary, #0054e9));height:56px}";

const TabBar = /*@__PURE__*/ proxyCustomElement(class TabBar extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.__attachShadow();
        this.ionTabBarChanged = createEvent(this, "ionTabBarChanged", 7);
        this.ionTabBarLoaded = createEvent(this, "ionTabBarLoaded", 7);
        this.keyboardCtrl = null;
        this.didLoad = false;
        this.keyboardVisible = false;
        /**
         * If `true`, the tab bar will be translucent.
         * Only applies when the theme is `"ios"` and the device supports
         * [`backdrop-filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter#Browser_compatibility).
         */
        this.translucent = false;
        /**
         * Set to `"compact"` to display a width based on the items
         * inside the tab bar. This value will only work for the
         * `ionic` theme.
         *
         * Set to `"full"` to display a full width tab bar.
         *
         * Defaults to `"full"`.
         */
        this.expand = 'full';
    }
    selectedTabChanged() {
        // Skip the initial watcher call that happens during component load
        // We handle that in componentDidLoad to ensure children are ready
        if (!this.didLoad) {
            return;
        }
        if (this.selectedTab !== undefined) {
            this.ionTabBarChanged.emit({
                tab: this.selectedTab,
            });
        }
    }
    componentDidLoad() {
        this.ionTabBarLoaded.emit();
        // Set the flag to indicate the component has loaded
        // This allows the watcher to emit changes from this point forward
        this.didLoad = true;
        // Emit the initial selected tab after the component is fully loaded
        // This ensures all child components (ion-tab-button) are ready
        if (this.selectedTab !== undefined) {
            this.ionTabBarChanged.emit({
                tab: this.selectedTab,
            });
        }
    }
    async connectedCallback() {
        this.keyboardCtrl = await createKeyboardController(async (keyboardOpen, waitForResize) => {
            /**
             * If the keyboard is hiding, then we need to wait
             * for the webview to resize. Otherwise, the tab bar
             * will flicker before the webview resizes.
             */
            if (keyboardOpen === false && waitForResize !== undefined) {
                await waitForResize;
            }
            this.keyboardVisible = keyboardOpen; // trigger re-render by updating state
        });
    }
    disconnectedCallback() {
        if (this.keyboardCtrl) {
            this.keyboardCtrl.destroy();
        }
    }
    getShape() {
        const theme = getIonTheme(this);
        const { shape } = this;
        // TODO(ROU-11234): Remove theme check when shapes are defined for all themes.
        if (theme !== 'ionic') {
            return undefined;
        }
        if (shape === undefined) {
            return 'round';
        }
        return shape;
    }
    render() {
        const { color, translucent, keyboardVisible, expand } = this;
        const theme = getIonTheme(this);
        const shape = this.getShape();
        const shouldHide = keyboardVisible && this.el.getAttribute('slot') !== 'top';
        return (h(Host, { key: 'c659f0d907c52602880822351d21c78339d2b6d3', role: "tablist", "aria-hidden": shouldHide ? 'true' : null, class: createColorClasses(color, {
                [theme]: true,
                'tab-bar-translucent': translucent,
                'tab-bar-hidden': shouldHide,
                [`tab-bar-${expand}`]: true,
                [`tab-bar-${shape}`]: shape !== undefined,
            }) }, h("slot", { key: '34000fa9365e40f29a7aaf9669b523292b304af8' })));
    }
    get el() { return this; }
    static get watchers() { return {
        "selectedTab": ["selectedTabChanged"]
    }; }
    static get style() { return {
        ionic: tabBarIonicCss,
        ios: tabBarIosCss,
        md: tabBarMdCss
    }; }
}, [289, "ion-tab-bar", {
        "color": [513],
        "selectedTab": [1, "selected-tab"],
        "translucent": [4],
        "expand": [1],
        "shape": [1],
        "keyboardVisible": [32]
    }, undefined, {
        "selectedTab": ["selectedTabChanged"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["ion-tab-bar"];
    components.forEach(tagName => { switch (tagName) {
        case "ion-tab-bar":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, TabBar);
            }
            break;
    } });
}

const IonTabBar = TabBar;
const defineCustomElement = defineCustomElement$1;

export { IonTabBar, defineCustomElement };
