import '../../assert/js/assert.js';
import '../../globals.js';
import optionize, { combineOptions } from '../../phet-core/js/optionize.js';
import StarNode from '../../scenery-phet/js/StarNode.js';
import { HBox } from '../../scenery/js/imports.js';
import vegas from './vegas.js';
export default class ScoreDisplayStars extends HBox {
    constructor(scoreProperty, providedOptions) {
        const options = optionize()({
            // SelfOptions
            numberOfStars: 1,
            perfectScore: 1,
            starNodeOptions: {
                starShapeOptions: {
                    outerRadius: 10,
                    innerRadius: 5
                },
                filledLineWidth: 1.5,
                emptyLineWidth: 1.5
            },
            // HBoxOptions
            spacing: 3
        }, providedOptions);
        const numberOfStars = options.numberOfStars;
        const perfectScore = options.perfectScore;
        super(options);
        // Update visibility of filled and half-filled stars based on score.
        const scorePropertyListener = (score) => {
            assert && assert(score <= perfectScore, `Score ${score} exceeds perfect score ${perfectScore}`);
            const children = [];
            const proportion = score / perfectScore;
            const numFilledStars = Math.floor(proportion * numberOfStars);
            for (let i = 0; i < numFilledStars; i++) {
                children.push(new StarNode(combineOptions({ value: 1 }, options.starNodeOptions)));
            }
            const remainder = proportion * numberOfStars - numFilledStars;
            if (remainder > 1E-6) {
                children.push(new StarNode(combineOptions({ value: remainder }, options.starNodeOptions)));
            }
            const numEmptyStars = numberOfStars - children.length;
            for (let i = 0; i < numEmptyStars; i++) {
                children.push(new StarNode(combineOptions({ value: 0 }, options.starNodeOptions)));
            }
            this.children = children;
        };
        scoreProperty.link(scorePropertyListener);
        this.disposeScoreDisplayStars = function () {
            scoreProperty.unlink(scorePropertyListener);
        };
    }
    dispose() {
        this.disposeScoreDisplayStars();
        super.dispose();
    }
}
vegas.register('ScoreDisplayStars', ScoreDisplayStars);
//# sourceMappingURL=ScoreDisplayStars.js.map