'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-9a9efa1c.js');

const pnBonusProgressbarCss = "pn-button-dropdown .pn-button-dropdown>pn-button>.pn-button{min-height:initial}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0}@media screen and (max-width: 767px){.sr-only-mobile{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0}}pn-bonus-progressbar{width:100%}.bonusprogressbar-top{display:flex;align-items:center;margin-bottom:1.6rem}.bonusprogressbar-top-icon{border-radius:100%;height:5rem;width:5rem;padding:1rem;display:inline-flex;margin-right:1em;margin-left:0.5em;background-color:#e0f8ff}[theme=red] .bonusprogressbar-top-icon{background-color:#fbc2c1}.bonusprogressbar-top-icon pn-icon svg{width:100%;height:100%}.bonusprogressbar-sumtext{margin-top:0.4rem;font-size:1.3rem;color:#5e554a}.bonusprogressbar-top-percentage{margin-left:0.8rem;padding:0}.bonusprogressbar-wrapper{position:relative;display:flex;min-height:5em;align-items:center}.bonusprogressbar-currentlevel{position:absolute}.bonusprogressbar-progress[value]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;height:1.7rem;border:0.1rem solid #00a0d6;border-radius:1.7rem;padding:0;margin:0;overflow:hidden}[theme=red] .bonusprogressbar-progress[value]{border-color:#f06365}.bonusprogressbar-progress[value]::-webkit-progress-bar{border:0;border-radius:1.7rem;margin:0;padding:0;background:#e0f8ff}[theme=red] .bonusprogressbar-progress[value]::-webkit-progress-bar{background:#fdefee}.bonusprogressbar-progress[value]::-webkit-progress-value{margin:0;padding:0;border-radius:1.7rem;background:#00a0d6}[theme=red] .bonusprogressbar-progress[value]::-webkit-progress-value{background:#f06365}";
const PnBonusProgressbarStyle0 = pnBonusProgressbarCss;

const PnBonusProgressbar = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.icon = null;
        this.heading = '';
        this.sumtext = null;
        this.theme = 'blue';
        this.bonuspercentage = '0%';
        this.currency = 'kr';
        this.value = 0;
        this.min = 0;
        this.max = 0;
        this.valuepercentage = 0;
        this.progresspercentage = 0;
        this.levelValues = [];
        this.currentLevelAdjustedValue = 0;
    }
    get hostElement() { return index.getElement(this); }
    componentWillLoad() {
        this.setInitialValues();
        this.setValuePercentage();
    }
    setInitialValues() {
        const levelElements = Array.from(this.hostElement.querySelectorAll('pn-bonus-progressbar-level:not([current])'));
        this.currentLevelAdjustedValue = this.value;
        this.levelValues = levelElements.map(elm => {
            return parseInt(elm.getAttribute('value'), 10);
        });
        if (!this.max) {
            if (this.levelValues && this.levelValues.length > 0) {
                const newMax = this.levelValues.slice(-1)[0];
                let modifier = 1.05;
                if (this.value > newMax) {
                    modifier = 1.2;
                }
                this.max = Math.floor(newMax * modifier); // This sets the max value which all levels are relative to
            }
        }
        // if (!this.min) {
        //   const suggestedMin = Math.floor(this.value * 0.9);
        //   if (suggestedMin > 0) {
        //     this.min = suggestedMin;
        //   }
        // }
        if (this.value > this.max) {
            this.currentLevelAdjustedValue = 100;
        }
    }
    setValuePercentage() {
        this.valuepercentage = (this.value / this.max) * 100;
        this.progresspercentage = ((this.value - this.min) / (this.max - this.min)) * 100;
        if (this.progresspercentage < 0) {
            if (this.levelValues && this.levelValues.length && this.levelValues[0] < this.value) {
                this.min = Math.floor(this.levelValues[0] * 0.95);
            }
            else {
                this.min = Math.floor(this.value * 0.95);
            }
        }
        if (this.progresspercentage > 100) {
            this.progresspercentage = 100;
            const newMax = this.levelValues.slice(-1)[0];
            let modifier = 1.05;
            if (this.value > newMax) {
                modifier = 1.2;
            }
            this.max = Math.floor(newMax * modifier); // This sets the max value which all levels are relative to
            // this.max = Math.floor(newMax * 1.20);
        }
    }
    iconColor() {
        switch (this.theme) {
            case 'red':
                return 'coral700';
            case 'blue':
            default:
                return 'blue700';
        }
    }
    render() {
        return (index.h(index.Host, { key: '0c2800a5ff59a29a2932257f625a86ec8217ab78' }, index.h("div", { key: 'd53c24cd81f61b5b71e8065b423108e70b37228e', class: "bonusprogressbar-top" }, this.icon ? (index.h("div", { class: "bonusprogressbar-top-icon" }, index.h("pn-icon", { icon: this.icon, small: "false", color: this.iconColor() }))) : ({}), index.h("div", { key: '4bf2dd629ee729f680f75e0bdb25d60ab29463cb', class: "bonusprogressbar-top-heading" }, index.h("h4", { key: 'c23baca714b75a70374c164c4af5fee0ac3df1a8', class: "bonusprogressbar-top-headline" }, this.heading, " ", index.h("strong", { key: 'aecfe379324384f06b23c648de1f902a6f233f62', class: "bonusprogressbar-top-percentage" }, this.bonuspercentage)), this.sumtext ? index.h("div", { class: "bonusprogressbar-sumtext" }, this.sumtext) : null)), index.h("div", { key: 'c4186c08abbf122d0895f030a836b5adbd4b4a6c', class: "bonusprogressbar-wrapper" }, index.h("progress", { key: '043df984daf3c135d4248c67e62d83ee4e1ea978', class: "bonusprogressbar-progress", value: this.progresspercentage, max: "100" }), index.h("slot", { key: 'adc85d4228cbbc28aa2846b78f753660cd7e366a' }))));
    }
    static get watchers() { return {
        "currentLevelAdjustedValue": ["setValuePercentage"],
        "value": ["setValuePercentage"],
        "min": ["setValuePercentage"],
        "max": ["setValuePercentage"]
    }; }
};
PnBonusProgressbar.style = PnBonusProgressbarStyle0;

exports.pn_bonus_progressbar = PnBonusProgressbar;

//# sourceMappingURL=pn-bonus-progressbar.cjs.entry.js.map