// Copyright 2021-2025, University of Colorado Boulder
/**
 * RichText that composes ReadingBlock, adding support for Voicing and input listeners that speak content upon
 * user activation.
 *
 * Example usage:
 *   const voicingRichText = new VoicingRichText( 'Hello, world!' );
 *
 * Example usage:
 *   const voicingRichText = new VoicingRichText( 'Hello, world!', {
 *     accessibleParagraph: 'Custom Voicing Text'
 *   } );
 *
 * @author Jesse Greenberg (PhET Interactive Simulations)
 */
import '../../../../../globals.js';
import { assert } from '../../../../../scenerystack/assert.js';
import optionize from '../../../../../phet-core/js/optionize.js';
import ReadingBlock from '../../../accessibility/voicing/ReadingBlock.js';
import ReadingBlockHighlight from '../../../accessibility/voicing/ReadingBlockHighlight.js';
import RichText from '../../../nodes/RichText.js';
import scenery from '../../../scenery.js';
import assertMutuallyExclusiveOptions from '../../../../../phet-core/js/assertMutuallyExclusiveOptions.js';
class VoicingRichText extends ReadingBlock(RichText) {
    constructor(text, providedOptions) {
        // readingBlockDisabledTagName is an advanced option for cases where you need custom PDOM behavior for the
        // ReadingBlock. Use accessibleParagraph for most cases.
        assert && assertMutuallyExclusiveOptions(providedOptions, ['readingBlockDisabledTagName', 'accessibleName'], ['accessibleParagraph']);
        const options = optionize()({
            // {string|null} - if provided, alternative text that will be read that is different from the
            // visually displayed text
            readingBlockNameResponse: text,
            // voicing
            // default tag name for a ReadingBlock, but there are cases where you may want to override this (such as
            // RichText links)
            readingBlockTagName: 'button'
        }, providedOptions);
        if (options.readingBlockDisabledTagName) {
            // If a custom tagName is provided for the ReadingBlock when Voicing is disabled, use accessibleName
            // for that PDOM content.
            options.accessibleName = options.accessibleName === undefined ? text : options.accessibleName;
        }
        else {
            // Otherwise, use accessibleParagraph so that the RichText will appear in the PDOM as a paragraph.
            options.accessibleParagraph = options.accessibleParagraph === undefined ? text : options.accessibleParagraph;
        }
        super(text, options);
        this.focusHighlight = new ReadingBlockHighlight(this);
    }
}
scenery.register('VoicingRichText', VoicingRichText);
export default VoicingRichText;
