var Wick = Wick || {};
Wick.PLP =  (function () {
    function bindEvents() {
        let $colorCard = $('.color-pick__color');
        let colorCardActive = 'color-pick__color-active';

        $('.rating-overlay').each(function () {

            let rating = $(this).attr("data-rating"),
                stars = $(this).children('.star-overlay');

            stars.each(function () {
                if(rating >= 1) {
                    rating--;
                } else if(rating < 1) {
                    rating = Math.asin( 2 * rating - 1 ) / Math.PI + 0.5;
                    $(this).css('width', rating + 'rem');
                    rating = 0;
                } else if (rating <= 0 ) {
                    $(this).css('width', '0rem');
                }

            });
        });

        function chooseColor() {
            $colorCard.click(function () {
                $(this).addClass(colorCardActive);
                $colorCard.unbind('click');
            })
        }
        chooseColor();
    }

    function init(){
        bindEvents();
    }

    init();
})();
