'use strict';

var index = require('./index-feA4skrY.js');
var tslib_es6 = require('./tslib.es6-DrfCPgT9.js');
var browser = require('./browser-BwmkTmm8.js');
var device = require('./device-CoogBamh.js');
var focusVisible = require('./focus-visible-DFZa8IIA.js');
var helpers = require('./helpers-HuaiWXrB.js');
var log = require('./log-CXDMiw7o.js');
var config_utils = require('./config.utils-Civnz2jT.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 = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.balAppReady = index.createEvent(this, "balAppReady");
        this.debouncedNotify = helpers.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 (browser.balBrowser.hasDocument && browser.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) {
            config_utils.updateBalAnimated(this.animated);
        }
        if (browser.balBrowser.hasWindow) {
            window.addEventListener('resize', this.debouncedNotify);
            this.debouncedNotify();
        }
    }
    componentDidLoad() {
        helpers.rIC(() => {
            this.ready = true;
            focusVisible.startFocusVisible();
        });
        helpers.rOnLoad(() => {
            if (browser.balBrowser.hasDocument && browser.balBrowser.hasWindow) {
                const doc = document.documentElement;
                doc.classList.add('lcp-ready');
                this.balAppReady.emit();
            }
        });
    }
    disconnectedCallback() {
        if (browser.balBrowser.hasWindow) {
            window.removeEventListener('resize', this.debouncedNotify);
        }
    }
    async setFocus(elements) {
        if (this.focusVisible) {
            this.focusVisible.setFocus(elements);
        }
    }
    render() {
        return (index.h(index.Host, { key: 'e6229236201fea92c4ccb1812f2f280a06130889', class: {
                'bal-app': true,
                'bal-app--safari': browser.balBrowser.isSafari,
                'bal-app--touch': device.balDevice.hasTouchScreen,
            } }, index.h("slot", { key: '7712c7609c709dbe754eaf5700fd43ca3992a39f' })));
    }
    get el() { return index.getElement(this); }
};
tslib_es6.__decorate([
    log.Logger('bal-app'),
    tslib_es6.__metadata("design:type", Function),
    tslib_es6.__metadata("design:paramtypes", [Function]),
    tslib_es6.__metadata("design:returntype", void 0)
], App.prototype, "createLogger", null);
App.style = balAppCss;

exports.bal_app = App;
