import '../../../chipper/js/initialize-globals.js';
import '../../../assert/js/assert.js';
import '../../../globals.js';
// Copyright 2024, University of Colorado Boulder
/**
 * Data pertaining to a hotkey, including keystrokes and associated metadata for documentation and the keyboard help
 * dialog.
 *
 * @author Jesse Greenberg (PhET Interactive Simulations)
 */
import DerivedProperty from '../../../axon/js/DerivedProperty.js';
import InstanceRegistry from '../../../phet-core/js/documentation/InstanceRegistry.js';
import optionize from '../../../phet-core/js/optionize.js';
import { KeyDescriptor, scenery } from '../../../scenery/js/imports.js';
export default class HotkeyData {
    constructor(providedOptions) {
        assert && assert(providedOptions.binderName || providedOptions.keyboardHelpDialogLabelStringProperty, 'You must provide some label for the hotkey');
        const options = optionize()({
            keyboardHelpDialogPDOMLabelStringProperty: null,
            keyboardHelpDialogLabelStringProperty: null,
            global: false,
            binderName: ''
        }, providedOptions);
        this.keyStringProperties = options.keyStringProperties;
        this.keyboardHelpDialogLabelStringProperty = options.keyboardHelpDialogLabelStringProperty;
        this.keyboardHelpDialogPDOMLabelStringProperty = options.keyboardHelpDialogPDOMLabelStringProperty;
        this.repoName = options.repoName;
        this.global = options.global;
        this.binderName = options.binderName;
        this.keyDescriptorsProperty = DerivedProperty.deriveAny(this.keyStringProperties, () => {
            return this.keyStringProperties.map(keyStringProperty => {
                return KeyDescriptor.keyStrokeToKeyDescriptor(keyStringProperty.value);
            });
        });
        // Add this Hotkey to the binder registry for documentation. See documentation in the binder repository
        // for more information about how this is done.
        assert && phet?.chipper?.queryParameters?.binder && InstanceRegistry.registerHotkey(this);
    }
    /**
     * Returns true if any of the keyStringProperties of this HotkeyData have the given keyStroke.
     */
    hasKeyStroke(keyStroke) {
        return this.keyStringProperties.some(keyStringProperty => keyStringProperty.value === keyStroke);
    }
    /**
     * Serialization for usage with binder (generated documentation).
     */
    serialize() {
        return {
            keyStrings: this.keyStringProperties.map(keyStringProperty => keyStringProperty.value),
            binderName: (this.binderName || this.keyboardHelpDialogLabelStringProperty?.value),
            repoName: this.repoName,
            global: this.global
        };
    }
    /**
     * Dispose of owned Properties to prevent memory leaks.
     */
    dispose() {
        this.keyDescriptorsProperty.dispose();
    }
    /**
     * Combine the keyStringProperties of an array of HotkeyData into a single array. Useful if you want to combine
     * multiple HotkeyData for a single KeyboardListener.
     */
    static combineKeyStringProperties(hotkeyDataArray) {
        return hotkeyDataArray.reduce((accumulator, hotkeyData) => {
            return accumulator.concat(hotkeyData.keyStringProperties);
        }, []);
    }
    /**
     * Returns true if any of the HotkeyData in the array have the given keyStroke.
     */
    static anyHaveKeyStroke(hotkeyDataArray, keyStroke) {
        return hotkeyDataArray.some(hotkeyData => hotkeyData.hasKeyStroke(keyStroke));
    }
}
scenery.register('HotkeyData', HotkeyData);
//# sourceMappingURL=HotkeyData.js.map