import '../../globals.js';
import { Shape } from '../../kite/js/imports.js';
import optionize from '../../phet-core/js/optionize.js';
import { Node, Path } from '../../scenery/js/imports.js';
import sceneryPhet from './sceneryPhet.js';
import StarShape from './StarShape.js';
class StarNode extends Node {
    constructor(providedOptions) {
        const options = optionize()({
            value: 1,
            emptyFill: '#e1e1e1', //pretty gray
            emptyStroke: '#d3d1d1 ', //darker gray than the fill, but still pretty faint
            emptyLineWidth: 1.5,
            emptyLineJoin: 'round',
            filledFill: '#fcff03',
            filledStroke: 'black',
            filledLineWidth: 1.5,
            filledLineJoin: 'round',
            starShapeOptions: {}
        }, providedOptions);
        super();
        // Add the gray star behind the filled star, so it will look like it fills in.
        const backgroundStar = new OptimizedStarPath({
            stroke: options.emptyStroke,
            fill: options.emptyFill,
            lineWidth: options.emptyLineWidth,
            lineJoin: options.emptyLineJoin,
            starShapeOptions: options.starShapeOptions
        });
        this.addChild(backgroundStar);
        // Add the foreground star, unless the value is too low to warrant it.
        if (options.value > 0) {
            const foregroundStar = new OptimizedStarPath({
                stroke: options.filledStroke,
                fill: options.filledFill,
                lineWidth: options.filledLineWidth,
                lineJoin: options.filledLineJoin,
                starShapeOptions: options.starShapeOptions
            });
            // Apply a clipArea instead of actually adjusting the star's shape. This is faster for startup (potentially
            // important given the optimization documentation already in this file), and gives a cleaner appearance.
            // See https://github.com/phetsims/area-model-common/issues/131.
            if (options.value < 1) {
                const unstrokedBounds = foregroundStar.starShapeBounds;
                const overlySafeBounds = unstrokedBounds.dilated(options.filledLineWidth * 1.5);
                foregroundStar.clipArea = Shape.bounds(overlySafeBounds.withMaxX(unstrokedBounds.left + options.value * unstrokedBounds.width));
            }
            this.addChild(foregroundStar);
        }
        this.mutate(options);
    }
}
/**
 * Internal class for the path that represents that stars.  This exists primarily to provide something that can provide
 * the bounds in a highly optimized way, since otherwise they are fairly computational expensive to compute.
 */
class OptimizedStarPath extends Path {
    constructor(providedOptions) {
        const options = optionize()({
            starShapeOptions: {}
        }, providedOptions);
        // optimization for faster creation and usage
        options.boundsMethod = 'none';
        // Create the shape that will be used for the path and the bounds.
        const starShape = new StarShape(options.starShapeOptions);
        super(starShape, options);
        // Pre-compute the bounds as an optimization.
        this.starShapeBounds = starShape.getBounds();
    }
    /**
     * override for the method used to compute the bounds, uses a pre-computed value
     */
    computeShapeBounds() {
        return this.starShapeBounds;
    }
}
sceneryPhet.register('StarNode', StarNode);
export default StarNode;
//# sourceMappingURL=StarNode.js.map