import '../../../assert/js/assert.js';
import '../../../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 sun from '../sun.js';
import RectangularButton from './RectangularButton.js';
import ToggleButtonInteractionStateProperty from './ToggleButtonInteractionStateProperty.js';
import ToggleButtonModel from './ToggleButtonModel.js';
export default class RectangularToggleButton extends RectangularButton {
    /**
     * @param property - axon Property that can be either valueOff or valueOn
     * @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) {
        assert && assert(property.valueComparisonStrategy === 'reference', 'RectangularToggleButton depends on "===" equality for value comparison');
        const options = optionize()({
            // {TSoundPlayer} - sounds to be played on toggle transitions
            valueOffSoundPlayer: sharedSoundPlayers.get('toggleOff'),
            valueOnSoundPlayer: sharedSoundPlayers.get('toggleOn'),
            // phet-io support
            tandem: Tandem.REQUIRED,
            phetioFeatured: true
        }, providedOptions);
        // Note it shares a tandem with this, so the emitter will be instrumented as a child of the button
        const toggleButtonModel = new ToggleButtonModel(valueOff, valueOn, property, options);
        const toggleButtonInteractionStateProperty = new ToggleButtonInteractionStateProperty(toggleButtonModel);
        super(toggleButtonModel, toggleButtonInteractionStateProperty, options);
        this.addLinkedElement(property, {
            tandemName: 'property'
        });
        // sound generation
        const playSounds = () => {
            if (property.value === valueOff) {
                options.valueOffSoundPlayer.play();
            }
            else if (property.value === valueOn) {
                options.valueOnSoundPlayer.play();
            }
        };
        this.buttonModel.produceSoundEmitter.addListener(playSounds);
        this.disposeRectangularToggleButton = () => {
            this.buttonModel.produceSoundEmitter.removeListener(playSounds);
            toggleButtonModel.dispose();
        };
    }
    dispose() {
        this.disposeRectangularToggleButton();
        super.dispose();
    }
}
sun.register('RectangularToggleButton', RectangularToggleButton);
//# sourceMappingURL=RectangularToggleButton.js.map