// Copyright 2022-2025, University of Colorado Boulder
/**
 * GameInfoDialog shows descriptions for the levels of a game.  Each description is on a separate line.
 * If the simulation supports the gameLevels query parameter (see getGameLevelsSchema.ts) the caller
 * can optionally provide options.gameLevels to control which descriptions are visible.
 *
 * @author Chris Malley (PixelZoom, Inc.)
 */
import '../../globals.js';
import _ from 'lodash';
import { assert } from '../../scenerystack/assert.js';
import ScreenView from '../../joist/js/ScreenView.js';
import optionize from '../../phet-core/js/optionize.js';
import PhetFont from '../../scenery-phet/js/PhetFont.js';
import VBox from '../../scenery/js/layout/nodes/VBox.js';
import Node from '../../scenery/js/nodes/Node.js';
import RichText from '../../scenery/js/nodes/RichText.js';
import Dialog from '../../sun/js/Dialog.js';
import Tandem from '../../tandem/js/Tandem.js';
import vegas from './vegas.js';
const DEFAULT_DESCRIPTION_TEXT_FONT = new PhetFont(24);
export default class GameInfoDialog extends Dialog {
    /**
     * @param levelDescriptions - level descriptions, in order of ascending level number
     * @param providedOptions
     */
    constructor(levelDescriptions, providedOptions) {
        const options = optionize()({
            descriptionTextOptions: {
                font: DEFAULT_DESCRIPTION_TEXT_FONT
            },
            vBoxOptions: {
                align: 'left',
                spacing: 20
            },
            maxContentWidth: 0.75 * ScreenView.DEFAULT_LAYOUT_BOUNDS.width,
            tandem: Tandem.REQUIRED
        }, providedOptions);
        // Constrain the width of the title, and ensure that the title can still be used with scenery DAG feature.
        if (options.title) {
            options.title = new Node({
                children: [options.title],
                maxWidth: options.maxContentWidth
            });
        }
        const descriptionNodes = levelDescriptions.map((levelDescription, index) => new RichText(levelDescription, optionize()({
            tandem: options.tandem.createTandem(`level${index}DescriptionText`)
        }, options.descriptionTextOptions)));
        // Hide descriptions for levels that are not included in options.gameLevels.
        // We must still create these Nodes so that the PhET-iO API is not changed.
        // While options.gameLevels is required, this guard is provided for .js sims that do not comply.
        if (options.gameLevels) {
            assert && assert(_.every(options.gameLevels, gameLevel => (Number.isInteger(gameLevel) && gameLevel > 0)), 'gameLevels must be positive integers');
            descriptionNodes.forEach((node, index) => {
                node.visible = options.gameLevels.includes(index + 1);
            });
        }
        // Vertical layout
        const content = new VBox(optionize()({
            children: descriptionNodes,
            maxWidth: options.maxContentWidth // scale all descriptions uniformly
        }, options.vBoxOptions));
        super(content, options);
        this.disposeGameInfoDialog = () => {
            descriptionNodes.forEach(node => node.dispose());
        };
    }
    dispose() {
        this.disposeGameInfoDialog();
        super.dispose();
    }
}
vegas.register('GameInfoDialog', GameInfoDialog);
