import '../../assert/js/assert.js';
import '../../globals.js';
import dotRandom from '../../dot/js/dotRandom.js';
import optionize from '../../phet-core/js/optionize.js';
import { FireListener, Plane } from '../../scenery/js/imports.js';
import EventType from '../../tandem/js/EventType.js';
import Tandem from '../../tandem/js/Tandem.js';
import sceneryPhet from './sceneryPhet.js';
export default class BarrierRectangle extends Plane {
    constructor(modalNodeStack, providedOptions) {
        const options = optionize()({
            fill: 'rgba( 0, 0, 0, 0.3 )',
            pickable: true,
            phetioReadOnly: true, // Disable controls in the PhET-iO Studio wrapper
            phetioEventType: EventType.USER,
            visiblePropertyOptions: {
                phetioState: false
            }
        }, providedOptions);
        super(options);
        const lengthListener = (numberOfBarriers) => {
            this.visible = (numberOfBarriers > 0);
        };
        modalNodeStack.lengthProperty.link(lengthListener);
        this.addInputListener(new FireListener({
            tandem: Tandem.OPT_OUT,
            phetioReadOnly: options.phetioReadOnly,
            fire() {
                assert && assert(modalNodeStack.length > 0, 'There must be a Node in the stack to hide.');
                // If fuzzing is enabled, close popups with a reduced probability, to improve testing coverage.
                // As of this writing, this addresses Dialogs and the PhET menu.
                // See https://github.com/phetsims/aqua/issues/136
                if (!phet.chipper.isFuzzEnabled() || dotRandom.nextDouble() < 0.005) {
                    modalNodeStack.get(modalNodeStack.length - 1).hide();
                }
            }
        }));
        this.disposeBarrierRectangle = () => {
            if (modalNodeStack.lengthProperty.hasListener(lengthListener)) {
                modalNodeStack.lengthProperty.unlink(lengthListener);
            }
        };
    }
    dispose() {
        this.disposeBarrierRectangle();
        super.dispose();
    }
}
sceneryPhet.register('BarrierRectangle', BarrierRectangle);
//# sourceMappingURL=BarrierRectangle.js.map