"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require("@angular/core");
var ratingBarBackgrounds_service_1 = require("./ratingBarBackgrounds.service");
var ratingBarClass_service_1 = require("./ratingBarClass.service");
var componentsDefaultTheme_1 = require("../componentsDefaultTheme");
var RatingBarComponent = (function () {
    function RatingBarComponent(defaultTheme) {
        this.useDefaultTheme = defaultTheme.useDefaultTheme;
        this.ratingBarClass = new ratingBarClass_service_1.RatingBarClassService();
        this.ratingBarBackgrounds = new ratingBarBackgrounds_service_1.RatingBarBackgroundService();
    }
    RatingBarComponent.prototype.ngOnInit = function () {
        this.backgroundClass = this.ratingBarBackgrounds.getBackground(this.background);
        if (!this.value) {
            this.value = 0;
        }
        this.updateValue(this.value);
        this.updateDimensions(this.width);
    };
    RatingBarComponent.prototype.ngOnChanges = function (changes) {
        if (changes.value) {
            this.updateValue(changes.value.currentValue);
        }
        if (changes.width) {
            this.updateDimensions(changes.width.currentValue);
        }
    };
    RatingBarComponent.prototype.updateValue = function (newValue) {
        if (newValue > this.max) {
            newValue = this.max;
        }
        else if (newValue < this.min) {
            newValue = this.min;
        }
        var confidenceScore = (newValue - this.min) / (this.max - this.min);
        this.barClass = this.ratingBarClass.getClass(confidenceScore);
        this.calculatedWidth = Math.round(confidenceScore * this.width);
    };
    RatingBarComponent.prototype.updateDimensions = function (totalWidth) {
        this.dimensions = {
            width: totalWidth + 2,
            height: this.height + 2,
        };
        this.updateValue(this.value);
    };
    return RatingBarComponent;
}());
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], RatingBarComponent.prototype, "value", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], RatingBarComponent.prototype, "min", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], RatingBarComponent.prototype, "max", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], RatingBarComponent.prototype, "width", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], RatingBarComponent.prototype, "height", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", String)
], RatingBarComponent.prototype, "background", void 0);
RatingBarComponent = __decorate([
    core_1.Component({
        selector: 'rlRatingBar',
        template: require('./ratingBar.html'),
    }),
    __metadata("design:paramtypes", [componentsDefaultTheme_1.DefaultTheme])
], RatingBarComponent);
exports.RatingBarComponent = RatingBarComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmF0aW5nQmFyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsicmF0aW5nQmFyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxzQ0FBa0Y7QUFFbEYsK0VBQTBHO0FBQzFHLG1FQUF5RjtBQUN6RixvRUFBeUQ7QUFpQnpELElBQWEsa0JBQWtCO0lBaUI5Qiw0QkFBWSxZQUEwQjtRQUNyQyxJQUFJLENBQUMsZUFBZSxHQUFHLFlBQVksQ0FBQyxlQUFlLENBQUM7UUFDcEQsSUFBSSxDQUFDLGNBQWMsR0FBRyxJQUFJLDhDQUFxQixFQUFFLENBQUM7UUFDbEQsSUFBSSxDQUFDLG9CQUFvQixHQUFHLElBQUkseURBQTBCLEVBQUUsQ0FBQztJQUM5RCxDQUFDO0lBRUQscUNBQVEsR0FBUjtRQUNDLElBQUksQ0FBQyxlQUFlLEdBQUcsSUFBSSxDQU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