"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var core_1 = require("@angular/core");
var lodash_1 = require("lodash");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __object = typescript_angular_utilities_1.services.object;
var __array = typescript_angular_utilities_1.services.array;
var __guid = typescript_angular_utilities_1.services.guid;
var componentsDefaultTheme_1 = require("../../componentsDefaultTheme");
var validationInput_1 = require("../validationInput");
var componentValidator_service_1 = require("../../../services/componentValidator/componentValidator.service");
var form_1 = require("../../form/form");
var UserRatingComponent = (function (_super) {
    __extends(UserRatingComponent, _super);
    function UserRatingComponent(defaultTheme, rlForm, componentValidator, object, array, guid) {
        var _this = _super.call(this, rlForm, componentValidator, object, array, guid) || this;
        _this.inputType = 'userRating';
        _this.initControl();
        _this.useDefaultTheme = defaultTheme.useDefaultTheme;
        return _this;
    }
    UserRatingComponent.prototype.ngOnInit = function () {
        var _this = this;
        _super.prototype.ngOnInit.call(this);
        var values = lodash_1.range(1, (this.range || 5) + 1).reverse();
        this.stars = lodash_1.map(values, function (value) {
            return {
                value: value,
                filled: false,
            };
        });
        this.updateStarView(this.value);
        this.control.valueChanges.subscribe(function (value) { return _this.updateStarView(value); });
    };
    UserRatingComponent.prototype.setRating = function (rating) {
        this.setValue(rating);
    };
    UserRatingComponent.prototype.updateStarView = function (rating) {
        lodash_1.each(this.stars, function (star) {
            if (star.value <= rating) {
                star.filled = true;
            }
            else {
                star.filled = false;
            }
        });
    };
    return UserRatingComponent;
}(validationInput_1.ValidatedInputComponent));
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], UserRatingComponent.prototype, "range", void 0);
UserRatingComponent = __decorate([
    core_1.Component({
        selector: 'rlUserRating',
        template: require('./userRating.html'),
        inputs: validationInput_1.validationInputs,
        outputs: validationInput_1.baseOutputs,
        providers: [componentValidator_service_1.ComponentValidator],
    }),
    __param(1, core_1.Optional()),
    __metadata("design:paramtypes", [componentsDefaultTheme_1.DefaultTheme,
        form_1.FormComponent,
        componentValidator_service_1.ComponentValidator, __object.ObjectUtility, __array.ArrayUtility, __guid.GuidService])
], UserRatingComponent);
exports.UserRatingComponent = UserRatingComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXNlclJhdGluZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInVzZXJSYXRpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsc0NBQW1FO0FBQ25FLGlDQUEwQztBQUUxQyw2RUFBd0Q7QUFDeEQsSUFBTyxRQUFRLEdBQUcsdUNBQVEsQ0FBQyxNQUFNLENBQUM7QUFDbEMsSUFBTyxPQUFPLEdBQUcsdUNBQVEsQ0FBQyxLQUFLLENBQUM7QUFDaEMsSUFBTyxNQUFNLEdBQUcsdUNBQVEsQ0FBQyxJQUFJLENBQUM7QUFFOUIsdUVBQTREO0FBRTVELHNEQUE0RjtBQUM1Riw4R0FBcUc7QUFDckcsd0NBQWdEO0FBY2hELElBQWEsbUJBQW1CO0lBQ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