import '../../tandem/js/PhetioIDUtils.js';
import '../../globals.js';
// Copyright 2021-2023, University of Colorado Boulder
/**
 * Abstract base class for the type that wires into an UtteranceQueue to announce Utterances.
 *
 * @author Michael Kauzmann (PhET Interactive Simulations)
 */
import Emitter from '../../axon/js/Emitter.js';
import optionize from '../../phet-core/js/optionize.js';
import PhetioObject from '../../tandem/js/PhetioObject.js';
import IOType from '../../tandem/js/types/IOType.js';
import NullableIO from '../../tandem/js/types/NullableIO.js';
import NumberIO from '../../tandem/js/types/NumberIO.js';
import OrIO from '../../tandem/js/types/OrIO.js';
import StringIO from '../../tandem/js/types/StringIO.js';
import Utterance from './Utterance.js';
import utteranceQueueNamespace from './utteranceQueueNamespace.js';
class Announcer extends PhetioObject {
    constructor(providedOptions) {
        const options = optionize()({
            respectResponseCollectorProperties: true,
            phetioType: Announcer.AnnouncerIO,
            phetioState: false
        }, providedOptions);
        super(options);
        // A flag that indicates to an UtteranceQueue that this Announcer is ready to speak the next Utterance.
        this.readyToAnnounce = true;
        // A flag that indicates whether this announcer has successfully spoken at least once.
        this.hasSpoken = false;
        this.respectResponseCollectorProperties = options.respectResponseCollectorProperties;
        this.announcementCompleteEmitter = new Emitter({
            parameters: [{
                    name: 'utterance', phetioType: Utterance.UtteranceIO
                }, {
                    name: 'text',
                    phetioType: NullableIO(OrIO([StringIO, NumberIO]))
                }],
            tandem: options.tandem?.createTandem('announcementCompleteEmitter'),
            phetioReadOnly: true,
            phetioDocumentation: 'The announcement that has just completed. The Utterance text could potentially differ from ' +
                'the exact text that was announced, so both are emitted. Use `text` for an exact match of what was announced.'
        });
    }
    /**
     * Determine if one utterance should cancel another. Default behavior for this superclass is to cancel when
     * the new Utterance is of higher priority. But subclasses may re-implement this function if it has special logic
     * or announcerOptions that override this behavior.
     */
    shouldUtteranceCancelOther(utterance, utteranceToCancel) {
        return utteranceToCancel.priorityProperty.value < utterance.priorityProperty.value;
    }
    /**
     * Intended to be overridden by subtypes if necessary as a way to order the queue if there is announcer
     * specific logic.
     */
    onUtterancePriorityChange(utterance) {
        // See subclass for implementation
    }
}
Announcer.AnnouncerIO = new IOType('AnnouncerIO', {
    valueType: Announcer,
    documentation: 'Announces text to a specific browser technology (like aria-live or web speech)'
});
utteranceQueueNamespace.register('Announcer', Announcer);
export default Announcer;
//# sourceMappingURL=Announcer.js.map