"use strict";
var angular = require("angular");
var componentsDefaultTheme_1 = require("../componentsDefaultTheme");
var ratingBarBackgrounds_service_1 = require("./ratingBarBackgrounds.service");
var ratingBarClass_service_1 = require("./ratingBarClass.service");
exports.moduleName = 'rl.ui.components.ratingBar';
exports.componentName = 'rlRatingBar';
exports.controllerName = 'RatingBarController';
var RatingBarController = (function () {
    function RatingBarController(useDefaultTheme) {
        this.useDefaultTheme = useDefaultTheme;
        var ratingBarBackgrounds = new ratingBarBackgrounds_service_1.RatingBarBackgroundService;
        this.ratingBarClass = new ratingBarClass_service_1.RatingBarClassService;
        this.backgroundClass = ratingBarBackgrounds.getBackground(this.background);
        if (this.value == null) {
            this.value = 0;
        }
        this.updateValue(this.value);
        this.updateDimensions(this.totalWidth);
    }
    RatingBarController.prototype.$onChanges = function (changes) {
        if (changes.value) {
            this.updateValue(changes.value.currentValue);
        }
        if (changes.totalWidth) {
            this.updateDimensions(changes.totalWidth.currentValue);
        }
    };
    RatingBarController.prototype.updateValue = function (newValue) {
        var confidenceScore = (newValue - this.min) / (this.max - this.min);
        this.barClass = this.ratingBarClass.getClass(confidenceScore);
        this.width = Math.round(confidenceScore * this.totalWidth);
    };
    RatingBarController.prototype.updateDimensions = function (totalWidth) {
        this.dimensions = {
            width: totalWidth + 2,
            height: this.height + 2,
        };
        this.updateValue(this.value);
    };
    return RatingBarController;
}());
RatingBarController.$inject = [componentsDefaultTheme_1.defaultThemeValueName];
exports.RatingBarController = RatingBarController;
var ratingBar = {
    template: "\n\t\t<div class=\"rating-bar\">\n\t\t\t<div class=\"{{ratingBar.backgroundClass}}\" ng-class=\"{ empty: ratingBar.value == ratingBar.min, 'default-theme': ratingBar.useDefaultTheme }\" ng-style=\"ratingBar.dimensions\">\n\t\t\t\t<div ng-class=\"ratingBar.barClass\" ng-style=\"{ width: ratingBar.width, height: ratingBar.height }\"></div>\n\t\t\t</div>\n\t\t</div>\n\t",
    controller: exports.controllerName,
    controllerAs: 'ratingBar',
    bindings: {
        totalWidth: '<width',
        height: '<',
        value: '<',
        min: '<',
        max: '<',
        background: '<',
    },
};
angular.module(exports.moduleName, [])
    .component(exports.componentName, ratingBar)
    .controller(exports.controllerName, RatingBarController);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmF0aW5nQmFyLm5nMS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInJhdGluZ0Jhci5uZzEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLGlDQUFtQztBQUVuQyxvRUFBa0U7QUFFbEUsK0VBQTBHO0FBQzFHLG1FQUF5RjtBQUk5RSxRQUFBLFVBQVUsR0FBVyw0QkFBNEIsQ0FBQztBQUNsRCxRQUFBLGFBQWEsR0FBVyxhQUFhLENBQUM7QUFDdEMsUUFBQSxjQUFjLEdBQVcscUJBQXFCLENBQUM7QUFxQjFEO0lBaUJDLDZCQUFtQixlQUF3QjtRQUF4QixvQkFBZSxHQUFmLGVBQWUsQ0FBUztRQUMxQyxJQUFJLG9CQUFvQixHQUFpQyxJQUFJLHlEQUEwQixDQUFDO1FBQ3hGLElBQUksQ0FBQyxjQUFjLEdBQUcsSUFBSSw4Q0FBcUIsQ0FBQztRQUVoRCxJQUFJLENBQUMsZUFBZSxHQUFHLG9CQUFvQixDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUM7UUFFM0UsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLEtBQUssSUFBSSxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQ3hCLElBQUksQ0FBQyxLQUFLLEdBQUcsQ0FBQyxDQUFDO1FBQ2hCLENBQUM7UUFFRCxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQztRQUM3QixJQUFJLENBQUMsZ0JBQWdCLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQ3hDLENBQUM7SUF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