import '../../../globals.js';
// Copyright 2015-2024, University of Colorado Boulder
/**
 * Shows the bounds of current fitted blocks.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Matrix3 from '../../../dot/js/Matrix3.js';
import { Shape } from '../../../kite/js/imports.js';
import { BackboneDrawable, FittedBlock, scenery, ShapeBasedOverlay } from '../imports.js';
export default class FittedBlockBoundsOverlay extends ShapeBasedOverlay {
    constructor(display, rootNode) {
        super(display, rootNode, 'canvasNodeBoundsOverlay');
    }
    addShapes() {
        const self = this; // eslint-disable-line @typescript-eslint/no-this-alias
        function processBackbone(backbone, matrix) {
            if (backbone.willApplyTransform) {
                matrix = matrix.timesMatrix(backbone.backboneInstance.relativeTransform.matrix);
            }
            backbone.blocks.forEach((block) => {
                processBlock(block, matrix);
            });
        }
        function processBlock(block, matrix) {
            if (block instanceof FittedBlock && !block.fitBounds.isEmpty()) {
                self.addShape(Shape.bounds(block.fitBounds).transformed(matrix), 'rgba(255,0,0,0.8)', true);
            }
            if (block.firstDrawable && block.lastDrawable) {
                for (let childDrawable = block.firstDrawable; childDrawable !== block.lastDrawable; childDrawable = childDrawable.nextDrawable) {
                    processDrawable(childDrawable, matrix);
                }
                processDrawable(block.lastDrawable, matrix);
            }
        }
        function processDrawable(drawable, matrix) {
            // How we detect backbones (for now)
            if (drawable instanceof BackboneDrawable) {
                processBackbone(drawable, matrix);
            }
        }
        processBackbone(this.display.rootBackbone, Matrix3.IDENTITY);
    }
}
scenery.register('FittedBlockBoundsOverlay', FittedBlockBoundsOverlay);
//# sourceMappingURL=FittedBlockBoundsOverlay.js.map