import _ from 'lodash';
import '../../../chipper/js/browser/initialize-globals.js';
import '../../../assert/js/assert.js';
import '../../../globals.js';
// Copyright 2014-2024, University of Colorado Boulder
/**
 * RoundPushButton is a round push button, used to initiate some action.
 *
 * @author John Blanco (PhET Interactive Simulations)
 * @author Sam Reid (PhET Interactive Simulations)
 */
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 PushButtonInteractionStateProperty from './PushButtonInteractionStateProperty.js';
import PushButtonModel from './PushButtonModel.js';
import RoundButton from './RoundButton.js';
export default class RoundPushButton extends RoundButton {
    constructor(providedOptions) {
        const options = optionize()({
            soundPlayer: sharedSoundPlayers.get('pushButton'),
            tandem: Tandem.REQUIRED
        }, providedOptions);
        // Save the listener and add it after creating the button model. This is done so that
        // the same code path is always used for adding listener, thus guaranteeing a consistent code path if addListener is
        // overridden, see https://github.com/phetsims/sun/issues/284.
        const listener = options.listener;
        const superOptions = _.omit(options, ['listener']);
        // Note it shares a tandem with this, so the emitter will be instrumented as a child of the button
        //TODO https://github.com/phetsims/sun/issues/749 Do not propagate providedOptions to both super() and PushButtonModel
        const pushButtonModel = new PushButtonModel(superOptions);
        super(pushButtonModel, new PushButtonInteractionStateProperty(pushButtonModel), superOptions);
        this.pushButtonModel = pushButtonModel;
        // add the listener that was potentially saved above
        listener && this.addListener(listener);
        // sound generation
        const playSound = () => { options.soundPlayer.play(); };
        pushButtonModel.produceSoundEmitter.addListener(playSound);
        this.disposeRoundPushButton = () => {
            pushButtonModel.produceSoundEmitter.removeListener(playSound);
            pushButtonModel.dispose();
        };
        // support for binder documentation, stripped out in builds and only runs when ?binder is specified
        assert && window.phet?.chipper?.queryParameters?.binder && InstanceRegistry.registerDataURL('sun', 'RoundPushButton', this);
    }
    dispose() {
        // The order of operations here is important - the view needs to be disposed first so that it is unhooked from
        // the model before the model is disposed.  If the model is disposed first, the view ends up trying to change some
        // of its Property values when it is disposed.  See https://github.com/phetsims/axon/issues/242.
        super.dispose();
        this.disposeRoundPushButton();
    }
    /**
     * Adds a listener that will be notified when the button fires.
     */
    addListener(listener) {
        this.pushButtonModel.addListener(listener);
    }
    /**
     * Removes a listener.
     */
    removeListener(listener) {
        this.pushButtonModel.removeListener(listener);
    }
}
sun.register('RoundPushButton', RoundPushButton);
//# sourceMappingURL=RoundPushButton.js.map