import _ from 'lodash';
import '../../globals.js';
// Copyright 2024, University of Colorado Boulder
/**
 * A RichDragListener that supports sounds for grab and release.
 *
 * @author Jesse Greenberg
 */
import { combineOptions, optionize3 } from '../../phet-core/js/optionize.js';
import { RichDragListener } from '../../scenery/js/imports.js';
import sharedSoundPlayers from '../../tambo/js/sharedSoundPlayers.js';
import sceneryPhet from './sceneryPhet.js';
// Default values for sounds used by both drag listeners.
const DEFAULT_SOUND_OPTIONS = {
    grabSoundPlayer: sharedSoundPlayers.get('grab'),
    releaseSoundPlayer: sharedSoundPlayers.get('release')
};
// Factored out of optionize for readability.
const SOUND_RICH_DRAG_LISTENER_DEFAULTS = _.assignIn({
    keyboardDragListenerSoundOptions: {},
    dragListenerSoundOptions: {}
}, DEFAULT_SOUND_OPTIONS);
class SoundRichDragListener extends RichDragListener {
    constructor(providedOptions) {
        const options = optionize3()({}, SOUND_RICH_DRAG_LISTENER_DEFAULTS, providedOptions);
        // Create options for each listener, combining the listener type specific options into the shared options.
        const dragListenerSoundOptions = combineOptions({}, options, options.dragListenerSoundOptions);
        const keyboardDragListenerSoundOptions = combineOptions({}, options, options.keyboardDragListenerSoundOptions);
        const dragListenerPressedSoundPlayer = dragListenerSoundOptions.grabSoundPlayer;
        const dragListenerReleasedSoundPlayer = dragListenerSoundOptions.releaseSoundPlayer;
        const keyboardDragListenerPressedSoundPlayer = keyboardDragListenerSoundOptions.grabSoundPlayer;
        const keyboardDragListenerReleasedSoundPlayer = keyboardDragListenerSoundOptions.releaseSoundPlayer;
        super(options);
        // Unlinks are not necessary because they are removed when the drag listeners are disposed.
        SoundRichDragListener.linkToDragEvents(this.dragListener, dragListenerPressedSoundPlayer, dragListenerReleasedSoundPlayer);
        SoundRichDragListener.linkToDragEvents(this.keyboardDragListener, keyboardDragListenerPressedSoundPlayer, keyboardDragListenerReleasedSoundPlayer);
    }
    /**
     * Plays the sounds when the drag listener is pressed or released.
     */
    static linkToDragEvents(dragListener, grabSound, releaseSound) {
        const isPressedListener = (isPressed) => {
            if (isPressed) {
                grabSound && grabSound.play();
            }
            else if (!dragListener.interrupted) {
                releaseSound && releaseSound.play();
            }
        };
        dragListener.isPressedProperty.link(isPressedListener);
    }
}
SoundRichDragListener.DEFAULT_SOUND_OPTIONS = DEFAULT_SOUND_OPTIONS;
export default SoundRichDragListener;
sceneryPhet.register('SoundRichDragListener', SoundRichDragListener);
//# sourceMappingURL=SoundRichDragListener.js.map