<?php
/*
** 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/>.
**/

/**
 * tetrisMAX widget view for Zabbix 6.0 / 6.2.
 *
 * ONE PRODUCT: the playfield comes from the shared GameMarkup builder - the
 * same bytes the 6.4+ view renders - and the game itself runs in the browser
 * from the same client. So the only thing that differs here is the envelope:
 * manifest-v1 answers with a JSON object instead of handing the pieces to
 * CWidgetView.
 *
 * @var CView $this
 * @var array $data
 */

use Modules\TetrisMAX\Includes\GameMarkup;

$output = [
	'name' => $data['name'],
	'body' => GameMarkup::build($data['game_parameters'])
];

if (($messages = getMessages()) !== null) {
	$output['messages'] = $messages->toString();
}

if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
	CProfiler::getInstance()->stop();
	$output['debug'] = CProfiler::getInstance()->make()->toString();
}

echo json_encode($output);
