import _ from 'lodash';
import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2021-2024, University of Colorado Boulder
/**
 * Displays a background for a given GridConstraint.
 *
 * NOTE: If there are "holes" in the GridBox/GridConstraint (where there is no cell content for an x/y position), then
 * there will be no background for where those cells (if added) would have been.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import assertMutuallyExclusiveOptions from '../../../../phet-core/js/assertMutuallyExclusiveOptions.js';
import optionize from '../../../../phet-core/js/optionize.js';
import { Node, Rectangle, scenery } from '../../imports.js';
export default class GridBackgroundNode extends Node {
    constructor(constraint, providedOptions) {
        // Don't permit fill/stroke when createCellBackground is provided
        assertMutuallyExclusiveOptions(providedOptions, ['createCellBackground'], ['fill', 'stroke']);
        const defaultCreateCellBackground = (cell) => {
            return Rectangle.bounds(cell.lastAvailableBounds, {
                fill: options.fill,
                stroke: options.stroke
            });
        };
        const options = optionize()({
            fill: 'white',
            stroke: 'black',
            createCellBackground: defaultCreateCellBackground
        }, providedOptions);
        super();
        this.constraint = constraint;
        this.createCellBackground = options.createCellBackground;
        this.layoutListener = this.update.bind(this);
        this.constraint.finishedLayoutEmitter.addListener(this.layoutListener);
        this.update();
        this.mutate(options);
    }
    update() {
        this.children = this.constraint.displayedCells.map(this.createCellBackground).filter(_.identity);
    }
    /**
     * Releases references
     */
    dispose() {
        this.constraint.finishedLayoutEmitter.removeListener(this.layoutListener);
        super.dispose();
    }
}
scenery.register('GridBackgroundNode', GridBackgroundNode);
//# sourceMappingURL=GridBackgroundNode.js.map