import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { _ as __decorate, a as __metadata } from './tslib.es6.js';
import { b as balBrowser } from './browser.js';
import { b as balDevice } from './device.js';
import { s as startFocusVisible } from './focus-visible.js';
import { l as debounce, m as rIC, n as rOnLoad } from './helpers.js';
import { L as Logger } from './log.js';
import { b as updateBalAnimated } from './config.utils.js';

const balAppCss = ":root{--bal-app-height:100%}.bal-app{position:relative}.lcp-wait{opacity:0;visibility:hidden;display:none}.lcp-ready .lcp-wait{opacity:inherit;visibility:inherit;display:inherit}";

const App = /*@__PURE__*/ proxyCustomElement(class App extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.balAppReady = createEvent(this, "balAppReady", 7);
        this.debouncedNotify = debounce(() => this.notifyResize(), 100);
        /**
         * Disables all animation inside the bal-app. Can be used for simplify e2e testing.
         */
        this.animated = true;
        /**
         * @internal Is `true` when DS components are ready to be shown.
         */
        this.ready = false;
        this.notifyResize = async () => {
            if (balBrowser.hasDocument && balBrowser.hasWindow) {
                const doc = document.documentElement;
                doc.style.setProperty('--bal-app-height', `${window.innerHeight}px`);
            }
        };
    }
    createLogger(log) {
        this.log = log;
    }
    connectedCallback() {
        if (this.animated === false) {
            updateBalAnimated(this.animated);
        }
        if (balBrowser.hasWindow) {
            window.addEventListener('resize', this.debouncedNotify);
            this.debouncedNotify();
        }
    }
    componentDidLoad() {
        rIC(() => {
            this.ready = true;
            startFocusVisible();
        });
        rOnLoad(() => {
            if (balBrowser.hasDocument && balBrowser.hasWindow) {
                const doc = document.documentElement;
                doc.classList.add('lcp-ready');
                this.balAppReady.emit();
            }
        });
    }
    disconnectedCallback() {
        if (balBrowser.hasWindow) {
            window.removeEventListener('resize', this.debouncedNotify);
        }
    }
    async setFocus(elements) {
        if (this.focusVisible) {
            this.focusVisible.setFocus(elements);
        }
    }
    render() {
        return (h(Host, { key: 'e6229236201fea92c4ccb1812f2f280a06130889', class: {
                'bal-app': true,
                'bal-app--safari': balBrowser.isSafari,
                'bal-app--touch': balDevice.hasTouchScreen,
            } }, h("slot", { key: '7712c7609c709dbe754eaf5700fd43ca3992a39f' })));
    }
    get el() { return this; }
    static get style() { return balAppCss; }
}, [260, "bal-app", {
        "animated": [516],
        "ready": [1540],
        "setFocus": [64]
    }]);
__decorate([
    Logger('bal-app'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", void 0)
], App.prototype, "createLogger", null);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["bal-app"];
    components.forEach(tagName => { switch (tagName) {
        case "bal-app":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, App);
            }
            break;
    } });
}

const BalApp = App;
const defineCustomElement = defineCustomElement$1;

export { BalApp, defineCustomElement };
