// Copyright 2015-2025, University of Colorado Boulder
/**
 * RectangularMomentaryButton is a rectangular momentary button that toggles a Property between 2 values.
 * The 'off value' is the value when the button is not pressed.
 * The 'on value' is the value when the button is pressed.
 *
 * TODO: Not supported with alternative input, see https://github.com/phetsims/scenery/issues/1117
 *
 * @author Chris Malley (PixelZoom, Inc.)
 */
import '../../../globals.js';
import '../../../chipper/js/browser/initialize-globals.js';
import optionize from '../../../phet-core/js/optionize.js';
import sharedSoundPlayers from '../../../tambo/js/sharedSoundPlayers.js';
import Tandem from '../../../tandem/js/Tandem.js';
import MomentaryButtonInteractionStateProperty from './MomentaryButtonInteractionStateProperty.js';
import MomentaryButtonModel from './MomentaryButtonModel.js';
import RectangularButton from './RectangularButton.js';
export default class RectangularMomentaryButton extends RectangularButton {
    /**
     * @param property
     * @param valueOff - value when the button is in the off state
     * @param valueOn - value when the button is in the on state
     * @param [providedOptions?]
     */
    constructor(property, valueOff, valueOn, providedOptions) {
        const options = optionize()({
            // SelfOptions
            valueOffSoundPlayer: sharedSoundPlayers.get('toggleOff'),
            valueOnSoundPlayer: sharedSoundPlayers.get('toggleOn'),
            tandem: Tandem.REQUIRED
        }, providedOptions);
        // Note it shares a tandem with this, so the emitter will be instrumented as a child of the button
        const buttonModel = new MomentaryButtonModel(valueOff, valueOn, property, options);
        super(buttonModel, new MomentaryButtonInteractionStateProperty(buttonModel), options);
        // sound generation
        const playSounds = () => {
            if (property.value === valueOff) {
                options.valueOffSoundPlayer.play();
            }
            else if (property.value === valueOn) {
                options.valueOnSoundPlayer.play();
            }
        };
        this.buttonModel.produceSoundEmitter.addListener(playSounds);
        // pdom - signify button is 'pressed' when down
        const setAriaPressed = () => this.setPDOMAttribute('aria-pressed', property.value === valueOn);
        property.link(setAriaPressed);
        this.disposeRectangularMomentaryButton = () => {
            property.unlink(setAriaPressed);
            buttonModel.produceSoundEmitter.removeListener(playSounds);
            buttonModel.dispose();
        };
        // support for binder documentation, stripped out in builds and only runs when ?binder is specified
        ;
    }
    dispose() {
        this.disposeRectangularMomentaryButton();
        super.dispose();
    }
}
//# sourceMappingURL=RectangularMomentaryButton.js.map