<?php declare(strict_types = 0);
/*
** Copyright (C) 2021-2026 initMAX s.r.o.
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/

namespace Modules\TetrisMAX\Includes;

/**
 * The playfield's HTML - written ONCE, rendered by both trees.
 *
 * MARKUP IS WRITTEN ONCE: views/widget.view.php (6.4 - 7.4) and
 * legacy/views/widgets/tetrismax.view.php (6.0/6.2) differ only in the
 * envelope they put this string into - CWidgetView on the newer line, a JSON
 * object on the older one. The board, the score panel and the severity bar are
 * the same bytes on every version, which is what stops a two-tree package
 * becoming two games.
 *
 * Deliberately plain PHP: it has to run on a frontend that has none of the
 * Zabbix\Widgets classes, so it names no Zabbix class at all.
 */
final class GameMarkup {

	/**
	 * @param array $game_parameters  Board size, starting pace, tetromino catalogue.
	 */
	public static function build(array $game_parameters): string {
		$game_parameters_attr = htmlspecialchars(json_encode($game_parameters), ENT_QUOTES, 'UTF-8');

		return <<<HTML
    <div class="tetrismax" data-game-parameters="{$game_parameters_attr}">
        <div class="header"></div>
        <div class="logo">
            <div class="image"></div>
        </div>
        <div class="bar">
            <div class="bar__item">
                <div class="image hidden"></div>
            </div>
            <div class="bar__item">
                <div class="image hidden"></div>
            </div>
            <div class="bar__item">
                <div class="image hidden"></div>
            </div>
            <div class="bar__item">
                <div class="image hidden"></div>
            </div>
            <div class="bar__item">
                <div class="image hidden"></div>
            </div>
            <div class="bar__item">
                <div class="image hidden"></div>
            </div>
        </div>
        <div class="tetrismax__board"></div>
        <div class="tetrismax__next score-item">
            <span class="score-item__label" data-id="next"></span>
            <div class="score-item__grid-container"></div>
        </div>
        <div class="tetrismax__score score-item">
            <span class="score-item__label" data-id="time"></span>
            <span class="score-item__value"></span>
        </div>
        <div class="tetrismax__level score-item">
            <span class="score-item__label" data-id="level"></span>
            <span class="score-item__value"></span>
        </div>
        <div class="tetrismax__lines score-item">
            <span class="score-item__label" data-id="lines"></span>
            <span class="score-item__value"></span>
        </div>
    </div>
HTML;
	}
}
