import '../../../chipper/js/initialize-globals.js';
import '../../../assert/js/assert.js';
import '../../../globals.js';
import InstanceRegistry from '../../../phet-core/js/documentation/InstanceRegistry.js';
import optionize from '../../../phet-core/js/optionize.js';
import sharedSoundPlayers from '../../../tambo/js/sharedSoundPlayers.js';
import Tandem from '../../../tandem/js/Tandem.js';
import sun from '../sun.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
        assert && phet?.chipper?.queryParameters?.binder && InstanceRegistry.registerDataURL('sun', 'RectangularMomentaryButton', this);
    }
    dispose() {
        this.disposeRectangularMomentaryButton();
        super.dispose();
    }
}
sun.register('RectangularMomentaryButton', RectangularMomentaryButton);
//# sourceMappingURL=RectangularMomentaryButton.js.map