import ngModule from '../../module';
import FormInput from '../form-input';
import './style.scss';

export default class Rating extends FormInput {
    constructor($element, $scope) {
        super($element, $scope);

        this.maxStars = 5;
        this.stars = [];
    }

    get field() {
        return super.field;
    }

    set field(value) {
        super.field = value;
        this.populateStars();
    }

    populateStars() {
        for (let i = 0; i < this.maxStars; i++) {
            const star = {isActive: false};
            if (i < this.field)
                star.isActive = true;

            this.stars.push(star);
        }
    }
}

ngModule.vnComponent('vnRating', {
    template: require('./index.html'),
    controller: Rating,
    bindings: {
        maxStars: '<?',
    }
});