'use strict';

var balFileUpload_type = require('./bal-file-upload.type-BzNkF3YQ.js');
var balClose_i18n = require('./bal-close.i18n-B3X5xlkl.js');
var date = require('./date-BPyuc34s.js');
var balInputStepper_i18n = require('./bal-input-stepper.i18n-D57DHpYR.js');
var balLabel_i18n = require('./bal-label.i18n-BcNNm9Es.js');
var balTimeInput_i18n = require('./bal-time-input.i18n-Bfr3EMVD.js');
var balStep_util = require('./bal-step.util-DQcaqybX.js');
var balTab_util = require('./bal-tab.util-DFGwGbfr.js');
var initialize = require('./initialize-7J6n8lOv.js');
var browser = require('./browser-BwmkTmm8.js');
var device = require('./device-CoogBamh.js');
var option = require('./option-kGk4eTdA.js');
var form = require('./form-BSlIiqcR.js');
var helpers = require('./helpers-HuaiWXrB.js');
var maskUtil = require('./mask-util-B8hrxmqO.js');
var scroll = require('./scroll-B_kvfDui.js');
var overlays = require('./overlays-DQGlu5jj.js');
var breakpoints_subject = require('./breakpoints.subject-CXJYXMpo.js');
var config_utils = require('./config.utils-Civnz2jT.js');
var config_default = require('./config.default-Cko-wpRU.js');
var listener = require('./listener-DspXpqzY.js');
var swipe_subject = require('./swipe.subject-iyL-XVHG.js');
require('./index-feA4skrY.js');
require('./tokens.esm-wVc8fBNC.js');
require('./log-CXDMiw7o.js');

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);
};

class BalOrientationSubject extends listener.Subject {
    constructor() {
        super(observer => observer.orientationListener(this.state));
        this.listener = new breakpoints_subject.BalWindowResizeListener();
        this.state = device.balDevice.orientation.toObject();
        this.listener.connect();
        this.listener.add(() => {
            const newState = device.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' && browser.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
                helpers.getAppRoot(document).appendChild(element);
                return new Promise(resolve => helpers.componentOnReady(element, resolve));
            });
        }
        return Promise.resolve();
    }
    async dismissAll(data, role) {
        if (browser.balBrowser.hasDocument) {
            const overlays$1 = overlays.getOverlays(document, this.tag);
            await Promise.all(overlays$1.map(o => o.dismiss(data, role)));
        }
    }
    dismiss(data, role, id) {
        if (browser.balBrowser.hasDocument) {
            const overlay = overlays.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 (browser.balBrowser.hasDocument) {
            return overlays.getOverlay(document, this.tag);
        }
        return;
    }
}
const balModalController = new BalModalController();

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

Object.defineProperty(exports, "FileUploadRejectionReason", {
    enumerable: true,
    get: function () { return balFileUpload_type.FileUploadRejectionReason; }
});
exports.i18nBalClose = balClose_i18n.i18nBalClose;
exports.BalDate = date.BalDate;
exports.i18nBalDate = date.i18nBalDate;
exports.i18nBalInputStepper = balInputStepper_i18n.i18nBalInputStepper;
exports.i18nBalLabel = balLabel_i18n.i18nBalLabel;
exports.i18nBalTimeInput = balTimeInput_i18n.i18nBalTimeInput;
exports.newBalStepOption = balStep_util.newBalStepOption;
exports.newBalTabOption = balTab_util.newBalTabOption;
exports.BalSnackbarController = initialize.BalSnackbarController;
exports.BalToastController = initialize.BalToastController;
exports.balSnackbarController = initialize.balSnackbarController;
exports.balToastController = initialize.balToastController;
exports.initialize = initialize.initializeBaloiseDesignSystem;
exports.initializeBaloiseDesignSystem = initialize.initializeBaloiseDesignSystem;
exports.setupConfig = initialize.setupConfig;
exports.balBrowser = browser.balBrowser;
exports.BalDevice = device.BalDevice;
exports.balDevice = device.balDevice;
exports.newBalOption = option.newBalOption;
exports.scrollToFirstInvalidField = form.scrollToFirstInvalidField;
exports.componentOnReady = helpers.componentOnReady;
exports.deepReady = helpers.deepReady;
exports.getAppRoot = helpers.getAppRoot;
exports.isDescendant = helpers.isDescendant;
exports.shallowReady = helpers.shallowReady;
exports.wait = helpers.wait;
exports.waitAfterFramePaint = helpers.waitAfterFramePaint;
exports.waitAfterIdleCallback = helpers.waitAfterIdleCallback;
exports.waitAfterLargestContentfulPaintCallback = helpers.waitAfterLargestContentfulPaintCallback;
exports.waitForComponent = helpers.waitForComponent;
exports.waitForDesignSystem = helpers.waitForDesignSystem;
exports.waitOnLoadEventCallback = helpers.waitOnLoadEventCallback;
exports.INVALID_VALUE = maskUtil.INVALID_VALUE;
exports.BalScrollHandler = scroll.BalScrollHandler;
exports.BalBreakpointSubject = breakpoints_subject.BalBreakpointSubject;
exports.BalBreakpointsUtil = breakpoints_subject.BalBreakpointsUtil;
exports.balBreakpointSubject = breakpoints_subject.balBreakpointSubject;
exports.balBreakpoints = breakpoints_subject.balBreakpoints;
exports.attachToConfig = config_utils.attachToConfig;
exports.detachFromConfig = config_utils.detachFromConfig;
exports.onBalConfigChange = config_utils.onBalConfigChange;
exports.updateBalAllowedLanguages = config_utils.updateBalAllowedLanguages;
exports.updateBalAnimated = config_utils.updateBalAnimated;
exports.updateBalIcons = config_utils.updateBalIcons;
exports.updateBalLanguage = config_utils.updateBalLanguage;
exports.updateBalRegion = config_utils.updateBalRegion;
exports.useBalConfig = config_utils.useBalConfig;
exports.defaultConfig = config_default.defaultConfig;
exports.BalSwipeSubject = swipe_subject.BalSwipeSubject;
exports.BalModalController = BalModalController;
exports.BalOrientationSubject = BalOrientationSubject;
exports.NewBalOptionValue = NewBalOptionValue;
exports.NewBalSingleOptionValue = NewBalSingleOptionValue;
exports.balModalController = balModalController;
exports.balOrientationSubject = balOrientationSubject;
exports.getPlatforms = getPlatforms;
exports.hasTouchSupport = hasTouchSupport;
exports.i18nBalFieldLabel = i18nBalFieldLabel;
exports.isBrowser = isBrowser;
exports.isPlatform = isPlatform;
exports.newBalCheckboxOption = newBalCheckboxOption;
exports.newBalOptionValue = newBalOptionValue;
exports.newBalRadioOption = newBalRadioOption;
exports.newBalSingleOptionValue = newBalSingleOptionValue;
