import '../../globals.js';
// Copyright 2018-2024, University of Colorado Boulder
/**
 * StatusBar is the base class for the status bar that appears at the top of games. It sizes itself to match the bounds
 * of the browser window (the visible bounds) and float to either the top of the browser window or the layout bounds.
 * Subclasses are responsible for adding UI components to the bar.
 *
 * @author Chris Malley (PixelZoom, Inc.)
 */
import Property from '../../axon/js/Property.js';
import Bounds2 from '../../dot/js/Bounds2.js';
import optionize from '../../phet-core/js/optionize.js';
import PhetFont from '../../scenery-phet/js/PhetFont.js';
import { Color, Node, Rectangle } from '../../scenery/js/imports.js';
import sceneryPhet from './sceneryPhet.js';
class StatusBar extends Node {
    /**
     * @param layoutBounds
     * @param visibleBoundsProperty - visible bounds of the parent ScreenView
     * @param [providedOptions]
     */
    constructor(layoutBounds, visibleBoundsProperty, providedOptions) {
        const options = optionize()({
            // StatusBarOptions
            barFill: 'lightGray',
            barStroke: null,
            barHeight: 50,
            xMargin: 10,
            yMargin: 8,
            floatToTop: false,
            dynamicAlignment: true
        }, providedOptions);
        // size will be set by visibleBoundsListener
        const barNode = new Rectangle({
            fill: options.barFill,
            stroke: options.barStroke
        });
        // Support decoration, with the bar behind everything else
        const rectangles = [barNode];
        options.children = rectangles.concat(options.children || []);
        super(options);
        // for layout of UI components on the status bar, compensated for margins
        const positioningBoundsProperty = new Property(Bounds2.EVERYTHING, {
            valueType: Bounds2
        });
        this.positioningBoundsProperty = positioningBoundsProperty;
        const visibleBoundsListener = (visibleBounds) => {
            // Resize and position the bar to match the visible bounds.
            const y = (options.floatToTop) ? visibleBounds.top : layoutBounds.top;
            barNode.setRect(visibleBounds.minX, y, visibleBounds.width, options.barHeight);
            // Update the bounds inside which components on the status bar should be positioned.
            positioningBoundsProperty.value = new Bounds2(((options.dynamicAlignment) ? barNode.left : layoutBounds.minX) + options.xMargin, barNode.top, ((options.dynamicAlignment) ? barNode.right : layoutBounds.maxX) - options.xMargin, barNode.bottom);
        };
        visibleBoundsProperty.link(visibleBoundsListener);
        this.disposeStatusBar = () => {
            if (visibleBoundsProperty.hasListener(visibleBoundsListener)) {
                visibleBoundsProperty.unlink(visibleBoundsListener);
            }
        };
    }
    dispose() {
        this.disposeStatusBar();
        super.dispose();
    }
}
StatusBar.DEFAULT_FONT = new PhetFont(20);
StatusBar.DEFAULT_TEXT_FILL = Color.BLACK;
sceneryPhet.register('StatusBar', StatusBar);
export default StatusBar;
//# sourceMappingURL=StatusBar.js.map