(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('@angular/common')) :
    typeof define === 'function' && define.amd ? define('ngx-bootstrap/progressbar', ['exports', '@angular/core', 'ngx-bootstrap/utils', '@angular/common'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].progressbar = {}), global.ng.core, global.utils, global.ng.common));
}(this, (function (exports, i0, utils, common) { 'use strict';

    var ProgressbarConfig = /** @class */ (function () {
        function ProgressbarConfig() {
            /** if `true` changing value of progress bar will be animated */
            this.animate = false;
            /** maximum total value of progress element */
            this.max = 100;
        }
        return ProgressbarConfig;
    }());
    ProgressbarConfig.ɵprov = i0.ɵɵdefineInjectable({ factory: function ProgressbarConfig_Factory() { return new ProgressbarConfig(); }, token: ProgressbarConfig, providedIn: "root" });
    ProgressbarConfig.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];

    var ProgressbarComponent = /** @class */ (function () {
        function ProgressbarComponent(config) {
            this.isStacked = false;
            this._animate = false;
            this._max = 100;
            this.addClass = true;
            this.bars = [];
            Object.assign(this, config);
        }
        Object.defineProperty(ProgressbarComponent.prototype, "animate", {
            /** if `true` changing value of progress bar will be animated */
            set: function (value) {
                this._animate = value;
                this.bars.forEach(function (b) {
                    b.animate = value;
                });
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ProgressbarComponent.prototype, "striped", {
            /** If `true`, striped classes are applied */
            set: function (value) {
                this._striped = value;
                this.bars.forEach(function (b) {
                    b.striped = value;
                });
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ProgressbarComponent.prototype, "value", {
            /** current value of progress bar. Could be a number or array of objects
             * like {"value":15,"type":"info","label":"15 %"}
             */
            set: function (value) {
                this.isStacked = Array.isArray(value);
                if (typeof value === 'number') {
                    this._value = value;
                    this._values = void 0;
                }
                else {
                    this._value = void 0;
                    this._values = value;
                }
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ProgressbarComponent.prototype, "isBs3", {
            get: function () {
                return utils.isBs3();
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ProgressbarComponent.prototype, "max", {
            /** maximum total value of progress element */
            get: function () {
                return this._max;
            },
            set: function (v) {
                this._max = v;
                this.bars.forEach(function (bar) {
                    bar.recalculatePercentage();
                });
            },
            enumerable: false,
            configurable: true
        });
        ProgressbarComponent.prototype.addBar = function (bar) {
            bar.animate = this._animate;
            bar.striped = this._striped;
            this.bars.push(bar);
        };
        ProgressbarComponent.prototype.removeBar = function (bar) {
            this.bars.splice(this.bars.indexOf(bar), 1);
        };
        return ProgressbarComponent;
    }());
    ProgressbarComponent.decorators = [
        { type: i0.Component, args: [{
                    selector: 'progressbar',
                    template: "<bar [type]=\"type\" [value]=\"_value\" [max]=\"_max\" *ngIf=\"!isStacked\">\n  <ng-content></ng-content>\n</bar>\n<ng-template [ngIf]=\"isStacked\">\n  <bar *ngFor=\"let item of _values\" [type]=\"item.type\" [value]=\"item.value\" [max]=\"item.max\">{{ item.label }}</bar>\n</ng-template>\n",
                    styles: ["\n    :host {\n      width: 100%;\n      display: flex;\n    }\n  "]
                },] }
    ];
    ProgressbarComponent.ctorParameters = function () { return [
        { type: ProgressbarConfig }
    ]; };
    ProgressbarComponent.propDecorators = {
        animate: [{ type: i0.Input }],
        striped: [{ type: i0.Input }],
        type: [{ type: i0.Input }],
        value: [{ type: i0.Input }],
        max: [{ type: i0.HostBinding, args: ['attr.max',] }, { type: i0.Input }],
        addClass: [{ type: i0.HostBinding, args: ['class.progress',] }]
    };

    // todo: number pipe
    // todo: use query from progress?
    var BarComponent = /** @class */ (function () {
        function BarComponent(el, progress, renderer) {
            this.el = el;
            this.renderer = renderer;
            this.max = 100;
            this.addClass = true;
            this.animate = false;
            this.percent = 0;
            this.progress = progress;
        }
        Object.defineProperty(BarComponent.prototype, "setBarWidth", {
            get: function () {
                this.recalculatePercentage();
                return this.percent;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(BarComponent.prototype, "isBs3", {
            get: function () {
                return utils.isBs3();
            },
            enumerable: false,
            configurable: true
        });
        BarComponent.prototype.ngOnInit = function () {
            this.progress.addBar(this);
        };
        BarComponent.prototype.ngOnDestroy = function () {
            this.progress.removeBar(this);
        };
        BarComponent.prototype.ngOnChanges = function (changes) {
            if (changes.value) {
                if (!changes.value.currentValue && changes.value.currentValue !== 0) {
                    return;
                }
                this.value = changes.value.currentValue;
                this.recalculatePercentage();
            }
            if (changes.type) {
                this.type = changes.type.currentValue;
                this.applyTypeClasses();
            }
        };
        BarComponent.prototype.recalculatePercentage = function () {
            this.percent = +((this.value || 0) / this.progress.max * 100).toFixed(2);
            var totalPercentage = this.progress.bars
                .reduce(function (total, bar) {
                return total + bar.percent;
            }, 0);
            if (totalPercentage > 100) {
                this.percent -= totalPercentage - 100;
            }
        };
        BarComponent.prototype.applyTypeClasses = function () {
            if (this._prevType) {
                var barTypeClass = "progress-bar-" + this._prevType;
                var bgClass = "bg-" + this._prevType;
                this.renderer.removeClass(this.el.nativeElement, barTypeClass);
                this.renderer.removeClass(this.el.nativeElement, bgClass);
                this._prevType = void 0;
            }
            if (this.type) {
                var barTypeClass = "progress-bar-" + this.type;
                var bgClass = "bg-" + this.type;
                this.renderer.addClass(this.el.nativeElement, barTypeClass);
                this.renderer.addClass(this.el.nativeElement, bgClass);
                this._prevType = this.type;
            }
        };
        return BarComponent;
    }());
    BarComponent.decorators = [
        { type: i0.Component, args: [{
                    selector: 'bar',
                    template: "<ng-content></ng-content>\n",
                    // eslint-disable-next-line @angular-eslint/no-host-metadata-property
                    host: {
                        role: 'progressbar',
                        'aria-valuemin': '0',
                        '[class.progress-bar-animated]': '!isBs3 && animate',
                        '[class.progress-bar-striped]': 'striped',
                        '[class.active]': 'isBs3 && animate',
                        '[attr.aria-valuenow]': 'value',
                        '[attr.aria-valuetext]': 'percent ? percent.toFixed(0) + "%" : ""',
                        '[attr.aria-valuemax]': 'max',
                        '[style.height.%]': '"100"'
                    }
                },] }
    ];
    BarComponent.ctorParameters = function () { return [
        { type: i0.ElementRef },
        { type: ProgressbarComponent, decorators: [{ type: i0.Host }] },
        { type: i0.Renderer2 }
    ]; };
    BarComponent.propDecorators = {
        max: [{ type: i0.Input }],
        type: [{ type: i0.Input }],
        value: [{ type: i0.Input }],
        setBarWidth: [{ type: i0.HostBinding, args: ['style.width.%',] }],
        addClass: [{ type: i0.HostBinding, args: ['class.progress-bar',] }]
    };

    var ProgressbarModule = /** @class */ (function () {
        function ProgressbarModule() {
        }
        ProgressbarModule.forRoot = function () {
            return { ngModule: ProgressbarModule, providers: [] };
        };
        return ProgressbarModule;
    }());
    ProgressbarModule.decorators = [
        { type: i0.NgModule, args: [{
                    imports: [common.CommonModule],
                    declarations: [BarComponent, ProgressbarComponent],
                    exports: [BarComponent, ProgressbarComponent]
                },] }
    ];

    /**
     * Generated bundle index. Do not edit.
     */

    exports.BarComponent = BarComponent;
    exports.ProgressbarComponent = ProgressbarComponent;
    exports.ProgressbarConfig = ProgressbarConfig;
    exports.ProgressbarModule = ProgressbarModule;

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

})));
//# sourceMappingURL=ngx-bootstrap-progressbar.umd.js.map
