import { balBrowser } from "../browser";
import { BREAKPOINTS_MAP } from "./breakpoints.map";
export class BalBreakpointsUtil {
    constructor() {
        this.breakpoints = [];
        if (balBrowser.hasWindow) {
            this.win = window;
            this.win.BaloiseDesignSystem = this.win.BaloiseDesignSystem || {};
            this.detect();
        }
    }
    /**
     * Is true when mobile breakpoint is active
     */
    get isMobile() {
        return this.includes('mobile');
    }
    /**
     * Is true when tablet breakpoint is active
     */
    get isTablet() {
        return this.includes('tablet');
    }
    /**
     * Is true when mobile or tablet breakpoint is active
     */
    get isTouch() {
        return this.includes('touch');
    }
    /**
     * Is true when desktop, highDefinition, widescreen or fullhd breakpoint is active
     */
    get isDesktop() {
        return this.includes('desktop');
    }
    /**
     * Is true when highDefinition breakpoint is active
     */
    get isHighDefinition() {
        return this.includes('highDefinition');
    }
    /**
     * Is true when widescreen breakpoint is active
     */
    get isWidescreen() {
        return this.includes('widescreen');
    }
    /**
     * Is true when fullhd breakpoint is active
     */
    get isFullHD() {
        return this.includes('fullhd');
    }
    /**
     * Verifies if given breakpoint is active
     * @param breakpoint
     * @returns boolean: True if breakpoint is active
     */
    includes(breakpoint) {
        var _a;
        this.detect();
        return !!((_a = this.breakpoints) === null || _a === void 0 ? void 0 : _a.includes(breakpoint));
    }
    /**
     * Detects breakpoints and updates state
     * @returns breakpoints: list of breakpoints which are active
     */
    detect() {
        if (this.win) {
            this.breakpoints = Object.keys(BREAKPOINTS_MAP).filter(p => BREAKPOINTS_MAP[p](this.win));
            this.win.BaloiseDesignSystem.breakpoints = this.breakpoints;
            this.win.BaloiseDesignSystem.platforms = this.breakpoints;
        }
        return this.breakpoints;
    }
    /**
     * Turns the breakpoints array to a object.
     * @returns Object with all the breakpoints
     */
    toObject() {
        return {
            mobile: this.breakpoints.includes('mobile'),
            tablet: this.breakpoints.includes('tablet'),
            touch: this.breakpoints.includes('touch'),
            desktop: this.breakpoints.includes('desktop'),
            highDefinition: this.breakpoints.includes('highDefinition'),
            widescreen: this.breakpoints.includes('widescreen'),
            fullhd: this.breakpoints.includes('fullhd'),
        };
    }
}
export const balBreakpoints = /*@__PURE__*/ new BalBreakpointsUtil();
