import { setPlatformHelpers } from '@stencil/core/internal/client';
export { getAssetPath, render, setAssetPath, setNonce, setPlatformOptions } from '@stencil/core/internal/client';
import { b as balBrowser } from './browser.js';
import { d as defaultConfig } from './config.default.js';
export { a as attachToConfig, d as detachFromConfig, o as onBalConfigChange, u as updateBalAllowedLanguages, b as updateBalAnimated, c as updateBalIcons, e as updateBalLanguage, f as updateBalRegion, g as useBalConfig } from './config.utils.js';
export { F as FileUploadRejectionReason } from './bal-file-upload.type.js';
export { i as i18nBalClose } from './bal-close.i18n.js';
export { i as i18nBalDate } from './bal-date.i18n.js';
export { i as i18nBalInputStepper } from './bal-input-stepper.i18n.js';
export { i as i18nBalLabel } from './bal-label.i18n.js';
export { i as i18nBalTimeInput } from './bal-time-input.i18n.js';
export { n as newBalStepOption } from './bal-step.util.js';
export { n as newBalTabOption } from './bal-tab.util.js';
import { b as balToastController, a as balSnackbarController } from './bal-toast.controller.js';
export { B as BalSnackbarController, c as BalToastController } from './bal-toast.controller.js';
import { b as balBreakpoints } from './breakpoints.subject.js';
export { B as BalBreakpointSubject, c as BalBreakpointsUtil, a as balBreakpointSubject } from './breakpoints.subject.js';
export { B as BalDate } from './date.js';
import { b as balDevice } from './device.js';
export { B as BalDevice } from './device.js';
export { n as newBalOption } from './option.js';
export { s as scrollToFirstInvalidField } from './form.js';
import { g as getAppRoot, c as componentOnReady } from './helpers.js';
export { d as deepReady, i as isDescendant, s as shallowReady, w as wait, a as waitAfterFramePaint, b as waitAfterIdleCallback, e as waitAfterLargestContentfulPaintCallback, f as waitForComponent, h as waitForDesignSystem, j as waitOnLoadEventCallback } from './helpers.js';
export { I as INVALID_VALUE } from './mask-util.js';
import './window-resize.subject.js';
import { B as BalWindowResizeListener } from './window-resize.listener.js';
import { S as Subject } from './listener.js';
export { B as BalScrollHandler } from './scroll.js';
export { B as BalSwipeSubject } from './swipe.subject.js';
import { g as getOverlays, a as getOverlay } from './overlays.js';

const BALOISE_ANIMATION_KEY = 'baloise-animated';

class Config {
    constructor() {
        this._componentObservers = [];
        this._observers = [];
        this._config = defaultConfig;
    }
    get locale() {
        return `${this._config.language}-${this._config.region}`;
    }
    get region() {
        return this._config.region;
    }
    set region(region) {
        if (region !== this._config.region) {
            this._config.region = region;
            this._notify();
        }
    }
    get language() {
        return this._config.language;
    }
    set language(language) {
        if (language !== this._config.language) {
            if (this._config.allowedLanguages.includes(language)) {
                this._config.language = language;
            }
            else {
                this._config.language = this._config.fallbackLanguage;
            }
            this._notify();
        }
    }
    get allowedLanguages() {
        return this._config.allowedLanguages;
    }
    set allowedLanguages(allowedLanguages) {
        if (allowedLanguages !== this._config.allowedLanguages) {
            this._config.allowedLanguages = allowedLanguages;
            this._notify();
        }
    }
    get icons() {
        return this._config.icons;
    }
    set icons(icons) {
        this._config.icons = Object.assign(Object.assign({}, this._config.icons), icons);
        this._notify();
    }
    get logger() {
        return this._config.logger;
    }
    set logger(logger) {
        this._config.logger = Object.assign({}, logger);
        this._notify();
    }
    get animated() {
        return this._config.animated;
    }
    set animated(animated) {
        this._config.animated = animated;
        this._notify();
    }
    get httpFormSubmit() {
        return this._config.httpFormSubmit;
    }
    set httpFormSubmit(httpFormSubmit) {
        this._config.httpFormSubmit = httpFormSubmit;
        this._notify();
    }
    attach(observer) {
        const isExist = this._observers.includes(observer);
        if (isExist) {
            return console.log('Subject: Observer has been attached already.');
        }
        this._observers.push(observer);
        observer.configChanged(this._config);
    }
    detach(observer) {
        const observerIndex = this._observers.indexOf(observer);
        if (observerIndex === -1) {
            return console.log('Subject: Nonexistent observer.');
        }
        this._observers.splice(observerIndex, 1);
    }
    attachComponent(observer) {
        const isExist = this._componentObservers.includes(observer);
        if (isExist) {
            return console.log('Subject: Observer has been attached already.');
        }
        this._componentObservers.push(observer);
        observer.configChanged(this._config);
    }
    detachComponent(observer) {
        const observerIndex = this._componentObservers.indexOf(observer);
        if (observerIndex === -1) {
            return console.log('Subject: Nonexistent observer.');
        }
        this._componentObservers.splice(observerIndex, 1);
    }
    toString() {
        return JSON.stringify(this._config);
    }
    reset(config) {
        this._config = Object.assign(Object.assign(Object.assign({}, this._config), config), { icons: Object.assign(Object.assign({}, this._config.icons), config.icons) });
        this._notify(false);
    }
    _notify(all = true) {
        for (const observer of this._componentObservers) {
            observer.configChanged(this._config);
        }
        if (all) {
            for (const observer of this._observers) {
                observer.configChanged(this._config);
            }
        }
    }
}
const config = /*@__PURE__*/ new Config();
const configFromLocalStorage = (win) => {
    try {
        const animated = JSON.parse(win.localStorage.getItem(BALOISE_ANIMATION_KEY));
        if (animated !== null) {
            return {
                animated,
            };
        }
        return {};
    }
    catch (e) {
        return {};
    }
};

const setupConfig = (userConfig = {}, win = {}) => {
    if (Object.keys(win).length === 0 && balBrowser.hasWindow) {
        win = window;
    }
    win.BaloiseDesignSystem = win.BaloiseDesignSystem || {};
    config.reset(Object.assign(Object.assign(Object.assign({}, configFromLocalStorage(win)), userConfig), { icons: Object.assign({}, userConfig.icons) }));
    win.BaloiseDesignSystem.config = config;
};

const i18nBalFieldLabel = {
    de: {
        optional: ' (optional)',
    },
    en: {
        optional: ' (optional)',
    },
    fr: {
        optional: ' (optionnel)',
    },
    it: {
        optional: ' (opzionale)',
    },
    nl: {
        optional: ' (optioneel)',
    },
    es: {
        optional: ' (opcional)',
    },
    pl: {
        optional: ' (opcjonalnie)',
    },
    pt: {
        optional: ' (opcional)',
    },
    sv: {
        optional: ' (frivillig)',
    },
    fi: {
        optional: ' (valinnainen)',
    },
};

const newBalCheckboxOption = (option) => {
    return Object.assign(Object.assign({ interface: 'checkbox', labelHidden: false, flat: false, disabled: false, readonly: false, required: false, nonSubmit: false, invalid: false, checked: false }, option), { label: '', html: option.label });
};

const newBalRadioOption = (option) => {
    return Object.assign(Object.assign({ interface: 'radio', labelHidden: false, flat: false, disabled: false, readonly: false, required: false, nonSubmit: false, invalid: false }, option), { label: '', html: option.label });
};

const newBalOptionValue = (value, label, disabled = false, data) => {
    return {
        value,
        label,
        disabled,
        data,
    };
};
const newBalSingleOptionValue = (valueAndLabel, disabled = false, data) => {
    return newBalOptionValue(valueAndLabel, valueAndLabel, disabled, data);
};

const tags = [
    "bal-accordion",
    "bal-accordion-details",
    "bal-accordion-summary",
    "bal-accordion-trigger",
    "bal-app",
    "bal-badge",
    "bal-button",
    "bal-button-group",
    "bal-card",
    "bal-card-actions",
    "bal-card-button",
    "bal-card-content",
    "bal-card-subtitle",
    "bal-card-title",
    "bal-carousel",
    "bal-carousel-item",
    "bal-check",
    "bal-checkbox",
    "bal-checkbox-group",
    "bal-close",
    "bal-content",
    "bal-data",
    "bal-data-item",
    "bal-data-label",
    "bal-data-value",
    "bal-date",
    "bal-date-calendar",
    "bal-date-calendar-cell",
    "bal-divider",
    "bal-dropdown",
    "bal-field",
    "bal-field-control",
    "bal-field-hint",
    "bal-field-label",
    "bal-field-message",
    "bal-file-upload",
    "bal-footer",
    "bal-form",
    "bal-form-col",
    "bal-form-grid",
    "bal-heading",
    "bal-hint",
    "bal-hint-text",
    "bal-hint-title",
    "bal-icon",
    "bal-input",
    "bal-input-date",
    "bal-input-group",
    "bal-input-slider",
    "bal-input-stepper",
    "bal-label",
    "bal-list",
    "bal-list-item",
    "bal-list-item-accordion-body",
    "bal-list-item-accordion-head",
    "bal-list-item-content",
    "bal-list-item-icon",
    "bal-list-item-subtitle",
    "bal-list-item-title",
    "bal-logo",
    "bal-modal",
    "bal-modal-body",
    "bal-modal-header",
    "bal-nav",
    "bal-nav-link",
    "bal-nav-link-grid",
    "bal-nav-link-grid-col",
    "bal-nav-link-group",
    "bal-nav-menu-bar",
    "bal-nav-menu-flyout",
    "bal-nav-meta-bar",
    "bal-navbar",
    "bal-navbar-brand",
    "bal-navbar-menu",
    "bal-navbar-menu-end",
    "bal-navbar-menu-start",
    "bal-notices",
    "bal-notification",
    "bal-number-input",
    "bal-option",
    "bal-option-list",
    "bal-pagination",
    "bal-popover",
    "bal-popover-content",
    "bal-popup",
    "bal-progress-bar",
    "bal-radio",
    "bal-radio-group",
    "bal-radio-icon",
    "bal-segment",
    "bal-segment-item",
    "bal-select",
    "bal-select-option",
    "bal-shape",
    "bal-sheet",
    "bal-snackbar",
    "bal-spinner",
    "bal-stack",
    "bal-stage",
    "bal-stage-back-link",
    "bal-stage-body",
    "bal-stage-foot",
    "bal-stage-head",
    "bal-stage-image",
    "bal-step-item",
    "bal-steps",
    "bal-switch",
    "bal-tab-item",
    "bal-table",
    "bal-tabs",
    "bal-tag",
    "bal-tag-group",
    "bal-text",
    "bal-textarea",
    "bal-time-input",
    "bal-toast",
    "bal-tooltip"
];

// generated by .build/version.js
const VERSION = '19.8.2-snapshot.1836-fa2b859be';

const initializeBaloiseDesignSystem = (userConfig = {}, platformConfig = undefined, win = {}) => {
    if (Object.keys(win).length === 0 && balBrowser.hasWindow) {
        win = window;
    }
    win.BaloiseDesignSystem = win.BaloiseDesignSystem || {};
    if (platformConfig) {
        setPlatformHelpers(platformConfig);
    }
    setupConfig(Object.assign(Object.assign({}, userConfig), platformConfig), win);
    win.BaloiseDesignSystem.toastController = balToastController;
    win.BaloiseDesignSystem.snackbarController = balSnackbarController;
    win.BaloiseDesignSystem.initialize = () => setupConfig(win.BaloiseDesignSystem.config, win);
    win.BaloiseDesignSystem.version = VERSION;
    if (userConfig._generateHydrateForCustomElementsOutput) {
        generateHydrateForCustomElementsOutput(tags);
    }
};
/**
 * This function generates the CSS needed for custom elements hydration and inserts it into the document head.
 * The CSS rules include styles for slot fallback and the hydrated class.
 *
 * This is copied from the Stencil core library.
 * src/runtime/bootstrap-lazy.ts
 */
const generateHydrateForCustomElementsOutput = (cmpTags = []) => {
    const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
    const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
    const win = typeof window !== 'undefined' ? window : {};
    if (!win.document) {
        console.warn('Stencil: No document found. Skipping bootstrapping lazy components.');
        return;
    }
    const head = win.document.head;
    const metaCharset = /* @__PURE__ */ head.querySelector('meta[charset]');
    const dataStyles = /* @__PURE__ */ win.document.createElement('style');
    if (cmpTags.length > 0) {
        dataStyles.textContent += SLOT_FB_CSS;
        dataStyles.textContent += cmpTags.sort() + HYDRATED_CSS;
        if (dataStyles.innerHTML.length) {
            dataStyles.setAttribute('data-styles', '');
            head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
        }
    }
};

class BalOrientationSubject extends Subject {
    constructor() {
        super(observer => observer.orientationListener(this.state));
        this.listener = new BalWindowResizeListener();
        this.state = balDevice.orientation.toObject();
        this.listener.connect();
        this.listener.add(() => {
            const newState = balDevice.orientation.toObject();
            if (!this.isEqual(newState)) {
                this.state = newState;
                this.notify(undefined);
            }
        });
    }
    attach(observer) {
        super.attach(observer);
        observer.orientationListener(this.state);
    }
    isEqual(newState) {
        return newState.landscape === this.state.landscape && newState.portrait === this.state.portrait;
    }
}
const balOrientationSubject = /*@__PURE__*/ new BalOrientationSubject();

class BalModalController {
    constructor() {
        this.tag = 'bal-modal';
    }
    create(options) {
        /* tslint:disable-next-line */
        if (typeof customElements !== 'undefined' && balBrowser.hasDocument) {
            return customElements.whenDefined(this.tag).then(() => {
                const element = document.createElement(this.tag);
                // convert the passed in overlay options into props
                // that get passed down into the new overlay
                Object.assign(element, options);
                // append the overlay element to the document body
                getAppRoot(document).appendChild(element);
                return new Promise(resolve => componentOnReady(element, resolve));
            });
        }
        return Promise.resolve();
    }
    async dismissAll(data, role) {
        if (balBrowser.hasDocument) {
            const overlays = getOverlays(document, this.tag);
            await Promise.all(overlays.map(o => o.dismiss(data, role)));
        }
    }
    dismiss(data, role, id) {
        if (balBrowser.hasDocument) {
            const overlay = getOverlay(document, this.tag, id);
            if (!overlay) {
                return Promise.reject('overlay does not exist');
            }
            return overlay.dismiss(data, role);
        }
        return Promise.resolve(false);
    }
    async getTop() {
        if (balBrowser.hasDocument) {
            return getOverlay(document, this.tag);
        }
        return;
    }
}
const balModalController = new BalModalController();

/**
 * deprecated: Please use balDevice.hasTouchScreen
 */
const hasTouchSupport = () => balDevice.hasTouchScreen;
/**
 * deprecated: Please use balBrowser.isSafari
 */
const isBrowser = (browser) => {
    if (browser === 'Safari') {
        return balBrowser.isSafari;
    }
    return false;
};
const getPlatforms = (_win) => balBreakpoints.detect();
const isPlatform = (winOrPlatform, platform) => {
    if (typeof winOrPlatform === 'string') {
        platform = winOrPlatform;
    }
    if (platform) {
        return balBreakpoints.detect().includes(platform);
    }
    return false;
};
/**
 * deprecated
 */
const NewBalOptionValue = newBalOptionValue;
const NewBalSingleOptionValue = newBalSingleOptionValue;

export { BalModalController, BalOrientationSubject, NewBalOptionValue, NewBalSingleOptionValue, balBreakpoints, balBrowser, balDevice, balModalController, balOrientationSubject, balSnackbarController, balToastController, componentOnReady, defaultConfig, getAppRoot, getPlatforms, hasTouchSupport, i18nBalFieldLabel, initializeBaloiseDesignSystem as initialize, initializeBaloiseDesignSystem, isBrowser, isPlatform, newBalCheckboxOption, newBalOptionValue, newBalRadioOption, newBalSingleOptionValue, setupConfig };
