import '../../../tandem/js/PhetioIDUtils.js';
import '../../../globals.js';
// Copyright 2022-2024, University of Colorado Boulder
/**
 * PlayPauseStepButtonGroup has a play & pause button, optional step-forward button, and optional step-back button.
 * It's typically a subcomponent of TimeControlNode, and was originally an inner class of TimeControlNode.
 *
 * @author Denzell Barnett (PhET Interactive Simulations)
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 * @author Chris Malley (PixelZoom, Inc.)
 * @author Jesse Greenberg (PhET Interactive Simulations)
 */
import SceneryPhetConstants from '../SceneryPhetConstants.js';
import PlayPauseButton from './PlayPauseButton.js';
import StepBackwardButton from './StepBackwardButton.js';
import StepForwardButton from './StepForwardButton.js';
import sceneryPhet from '../sceneryPhet.js';
import { HBox } from '../../../scenery/js/imports.js';
import optionize, { combineOptions } from '../../../phet-core/js/optionize.js';
import Tandem from '../../../tandem/js/Tandem.js';
import DerivedProperty from '../../../axon/js/DerivedProperty.js';
import BooleanIO from '../../../tandem/js/types/BooleanIO.js';
import SceneryPhetStrings from '../SceneryPhetStrings.js';
const DEFAULT_STEP_BUTTON_RADIUS = 15;
const DEFAULT_STEP_BUTTON_TOUCH_AREA_DILATION = 5;
export default class PlayPauseStepButtonGroup extends HBox {
    constructor(isPlayingProperty, providedOptions) {
        const options = optionize()({
            // {boolean} - if true, a StepForwardButton is included in the button group
            includeStepForwardButton: true,
            // {boolean} - if true, a StepBackwardButton is included in the button group
            includeStepBackwardButton: false,
            // {number} horizontal space between Play/Pause and Step buttons
            playPauseStepXSpacing: 10,
            // Options for the PlayPauseButton
            playPauseButtonOptions: {
                radius: SceneryPhetConstants.DEFAULT_BUTTON_RADIUS,
                touchAreaDilation: 5
            },
            // Options for the StepBackwardButton
            stepBackwardButtonOptions: {
                radius: DEFAULT_STEP_BUTTON_RADIUS,
                touchAreaDilation: DEFAULT_STEP_BUTTON_TOUCH_AREA_DILATION
            },
            // Options for the StepForwardButton
            stepForwardButtonOptions: {
                radius: DEFAULT_STEP_BUTTON_RADIUS,
                touchAreaDilation: DEFAULT_STEP_BUTTON_TOUCH_AREA_DILATION
            },
            // HBoxOptions
            resize: false, // don't change layout if playPauseButton resizes with scaleFactorWhenNotPlaying
            // phet-io
            tandem: Tandem.REQUIRED,
            tandemNameSuffix: 'ButtonGroup',
            // pdom
            tagName: 'div', // so that it can receive descriptions
            appendDescription: true,
            playingDescription: SceneryPhetStrings.a11y.playPauseStepButtonGroup.playingDescriptionStringProperty,
            pausedDescription: SceneryPhetStrings.a11y.playPauseStepButtonGroup.pausedDescriptionStringProperty
        }, providedOptions);
        // by default, the step buttons are enabled when isPlayingProperty is false, but only create a PhET-iO instrumented
        // Property if it is going to be used
        if ((!options.stepForwardButtonOptions.enabledProperty) || (!options.stepBackwardButtonOptions.enabledProperty)) {
            // This is clearer than having the variable names match exactly. Opt out below
            // eslint-disable-next-line phet/tandem-name-should-match
            const defaultEnabledProperty = DerivedProperty.not(isPlayingProperty, {
                tandem: options.tandem.createTandem('enabledProperty'),
                phetioValueType: BooleanIO
            });
            if (!options.stepForwardButtonOptions.enabledProperty) {
                options.stepForwardButtonOptions.enabledProperty = defaultEnabledProperty;
            }
            if (!options.stepBackwardButtonOptions.enabledProperty) {
                options.stepBackwardButtonOptions.enabledProperty = defaultEnabledProperty;
            }
        }
        const children = [];
        const playPauseButton = new PlayPauseButton(isPlayingProperty, combineOptions({
            tandem: options.tandem.createTandem('playPauseButton'),
            phetioDocumentation: 'Button to control the animation in the simulation. This will also stop the model from stepping.'
        }, options.playPauseButtonOptions));
        children.push(playPauseButton);
        let stepForwardButton = null;
        if (options.includeStepForwardButton) {
            stepForwardButton = new StepForwardButton(combineOptions({
                tandem: options.tandem.createTandem('stepForwardButton'),
                phetioDocumentation: 'Progress the simulation a single model step forwards.'
            }, options.stepForwardButtonOptions));
            children.push(stepForwardButton);
        }
        let stepBackwardButton = null;
        if (options.includeStepBackwardButton) {
            stepBackwardButton = new StepBackwardButton(combineOptions({
                phetioDocumentation: 'Progress the simulation a single model step backwards.',
                tandem: options.tandem.createTandem('stepBackwardButton')
            }, options.stepBackwardButtonOptions));
            children.unshift(stepBackwardButton);
        }
        options.spacing = options.playPauseStepXSpacing;
        options.children = children;
        super(options);
        this.playPauseButton = playPauseButton;
        const playingListener = (playing) => {
            this.descriptionContent = playing ? options.playingDescription : options.pausedDescription;
        };
        isPlayingProperty.link(playingListener);
        this.disposePlayPauseStepButtonGroup = () => {
            isPlayingProperty.unlink(playingListener);
            playPauseButton.dispose();
            stepForwardButton && stepForwardButton.dispose();
            stepBackwardButton && stepBackwardButton.dispose();
        };
    }
    /**
     * Get the center of the PlayPauseButton, in the local coordinate frame of the PlayPauseStepButtonGroup.
     */
    getPlayPauseButtonCenter() {
        return this.playPauseButton.center;
    }
    dispose() {
        this.disposePlayPauseStepButtonGroup();
        super.dispose();
    }
}
sceneryPhet.register('PlayPauseStepButtonGroup', PlayPauseStepButtonGroup);
//# sourceMappingURL=PlayPauseStepButtonGroup.js.map