/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { Component, Input } from '@angular/core';
import { RmService } from '@bidi/common-services';
import { createFeatureSelector, select, Store } from '@ngrx/store';
import { RatingsService } from './../ratings.service';
export class ContentRatingsComponent {
    /**
     * @param {?} rm
     * @param {?} ratingsService
     * @param {?} store
     */
    constructor(rm, ratingsService, store) {
        this.rm = rm;
        this.ratingsService = ratingsService;
        this.store = store;
        this.typeData = 'tt';
        this.averageTeacher = 0;
        this.averageStudent = 0;
        this.average = 100;
        this.averageStudentCal = 100;
        this.voteC = false;
        this.totalStudent = 0;
        this.totalTeacher = 0;
        this.total = 0;
        this.state$ = this.store.pipe(select(createFeatureSelector('@bidi/common-components Ratings')));
    }
    /**
     * @return {?}
     */
    ngOnInit() {
        if (this.resourceId) {
            this.ratingsService.getRatings(this.resourceId);
            /** @type {?} */
            const resourceId = this.resourceId;
            this.ratingsService.ratings$.subscribe(data => {
                /** @type {?} */
                let range = 0;
                /** @type {?} */
                let rangeTeachers = 0;
                /** @type {?} */
                let totalTeachers = 0;
                /** @type {?} */
                let rangeStudent = 0;
                /** @type {?} */
                let totalStudent = 0;
                /** @type {?} */
                let total = 0;
                /** @type {?} */
                let average = 100;
                data.map(function (d) {
                    if (d.id === resourceId) {
                        if (d.ratings && d.ratings.length > 0) {
                            d.ratings.map(function (r) {
                                range = range + parseInt(r.range, 0);
                                if (r.type === 'teacher') {
                                    rangeTeachers = rangeTeachers + parseInt(r.range, 0);
                                    totalTeachers++;
                                }
                                if (r.type === 'student') {
                                    rangeStudent = rangeStudent + parseInt(r.range, 0);
                                    totalStudent++;
                                }
                                total++;
                            });
                        }
                    }
                });
                average = range / total;
                this.average = (total === 0) ? 100 : (5 - average) * 20;
                this.averageStudentCal = (totalStudent === 0) ? 100 : (5 - (rangeStudent / totalStudent)) * 20;
                this.averageTeacher = (totalTeachers === 0) ? 0 : rangeTeachers / totalTeachers;
                this.averageStudent = (totalStudent === 0) ? 0 : rangeStudent / totalStudent;
                this.totalStudent = totalStudent;
                this.totalTeacher = totalTeachers;
                this.total = total;
            });
        }
    }
}
ContentRatingsComponent.decorators = [
    { type: Component, args: [{
                selector: 'bidi-content-ratings',
                template: "<div class=\"ratings columns\">\n    <div class=\"ec-stars-wrapper column is-4\" title=\"Valoracion global\">\n        <div *ngIf=\"typeData === 'tt'\" class=\"ec-stars-overlay\" [style.width.%]=\"average\"></div>\n        <div *ngIf=\"typeData === 'scl'\" class=\"ec-stars-overlay\" [style.width.%]=\"averageStudentCal\"></div>\n        \n        <!--<a href=\"#\" data-value=\"1\" title=\"Votar con 1 estrellas\">&#9829;</a>\n        <a href=\"#\" data-value=\"2\" title=\"Votar con 2 estrellas\">&#9829;</a>\n        <a href=\"#\" data-value=\"3\" title=\"Votar con 3 estrellas\">&#9829;</a>\n        <a href=\"#\" data-value=\"4\" title=\"Votar con 4 estrellas\">&#9829;</a>\n        <a href=\"#\" data-value=\"5\" title=\"Votar con 5 estrellas\">&#9829;</a>-->\n\n        <svg class=\"icon-heart icon\" *ngIf=\"average > 0\">\n          <use xlink:href=\"#icon-heart-full\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average >= 20\">\n          <use xlink:href=\"#icon-heart-full\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average >= 40\">\n          <use xlink:href=\"#icon-heart-full\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average >= 60\">\n          <use xlink:href=\"#icon-heart-full\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average >= 80\">\n          <use xlink:href=\"#icon-heart-full\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average == 0\">\n          <use xlink:href=\"#icon-heart-empty\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average <= 20\">\n          <use xlink:href=\"#icon-heart-empty\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average <= 40\">\n          <use xlink:href=\"#icon-heart-empty\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average <= 60\">\n          <use xlink:href=\"#icon-heart-empty\"></use>\n        </svg>\n        <svg class=\"icon-heart icon\" *ngIf=\"average <= 80\">\n          <use xlink:href=\"#icon-heart-empty\"></use>\n        </svg>\n    </div>\n    <!--\n    <div class=\"ratings-user columns\">\n        <div class=\"opinions column\" *ngIf=\"showOpinions\">\n            <span *ngIf=\"typeData === 'tt'\"> <span class=\"ff-tt-bold\">Opiniones: </span> {{ total }}</span>\n            <span *ngIf=\"typeData === 'scl'\"><span class=\"ff-tt-bold\">Opiniones:</span>  {{ totalStudent }}</span>\n        </div>\n        <div *ngIf=\"typeData === 'tt'\" class=\"column \" title=\"Valoraci\u00F3n de los docentes\">\n            <svg class=\"icon-university icon is-small\">\n              <use xlink:href=\"#icon-university\"></use>\n            </svg>\n            <span>{{ averageTeacher| number: '1.1-2' }}</span>\n        </div>\n        <div class=\"column\" [title]=\"typeData === 'tt' ? 'Valoraci\u00F3n de los estudiantes': 'Valoracion de otros estudiantes'\">\n            <svg class=\"icon-graduation-cap icon is-small\" >\n              <use xlink:href=\"#icon-graduation-cap\"></use>\n            </svg>\n            <span >{{ averageStudent| number: '1.1-2' }}</span>\n        </div>--><br>\n        <bidi-content-views [views]=\"views\"></bidi-content-views>\n    </div>",
                styles: [".ratings{margin-left:0;display:block!important}.ratings .columns .column{padding:0}.ratings .icon{width:.9375rem;margin-right:6px}.ratings-user{padding-top:2%}.ratings-user .column{padding-right:0}.ratings-user .column svg{height:.65rem;width:.65rem}.content-vote{width:23%}.vote{margin-left:5%}.vote-start{margin-top:-15%}.ec-stars-wrapper{font-size:0;display:inline-block;position:relative;padding:0;margin-right:5%}.ec-stars-wrapper a{text-decoration:none;display:inline-block;font-size:2rem;color:#00cefa}.ec-stars-overlay{position:absolute;height:100%;right:0;top:0;background-color:rgba(255,255,255,.5);zoom:1}"]
            }] }
];
/** @nocollapse */
ContentRatingsComponent.ctorParameters = () => [
    { type: RmService },
    { type: RatingsService },
    { type: Store }
];
ContentRatingsComponent.propDecorators = {
    resourceId: [{ type: Input }],
    typeData: [{ type: Input }],
    views: [{ type: Input }],
    showOpinions: [{ type: Input }]
};
if (false) {
    /** @type {?} */
    ContentRatingsComponent.prototype.resourceId;
    /** @type {?} */
    ContentRatingsComponent.prototype.typeData;
    /** @type {?} */
    ContentRatingsComponent.prototype.views;
    /** @type {?} */
    ContentRatingsComponent.prototype.showOpinions;
    /** @type {?} */
    ContentRatingsComponent.prototype.averageTeacher;
    /** @type {?} */
    ContentRatingsComponent.prototype.averageStudent;
    /** @type {?} */
    ContentRatingsComponent.prototype.average;
    /** @type {?} */
    ContentRatingsComponent.prototype.averageStudentCal;
    /** @type {?} */
    ContentRatingsComponent.prototype.voteC;
    /** @type {?} */
    ContentRatingsComponent.prototype.totalStudent;
    /** @type {?} */
    ContentRatingsComponent.prototype.totalTeacher;
    /** @type {?} */
    ContentRatingsComponent.prototype.total;
    /**
     * @type {?}
     * @private
     */
    ContentRatingsComponent.prototype.state$;
    /**
     * @type {?}
     * @private
     */
    ContentRatingsComponent.prototype.rm;
    /** @type {?} */
    ContentRatingsComponent.prototype.ratingsService;
    /**
     * @type {?}
     * @private
     */
    ContentRatingsComponent.prototype.store;
}
//# sourceMappingURL=data:application/json;base64, 