<?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;

use Modules\TetrisMAX\Services\WidgetTranslator;
use Zabbix\Widgets\CWidgetForm;
use Zabbix\Widgets\Fields\CWidgetFieldRadioButtonList;

/**
 * tetrisMAX widget form (Zabbix 6.4 - 7.4).
 *
 * One setting, and it is the only one the game can honestly offer: how fast
 * the pieces fall to begin with. Everything else about a game of Tetris is
 * decided by playing it.
 *
 * The form used to carry four more controls - two item pickers, an API URL and
 * an API token - for a scoring endpoint that has been removed. The widget no
 * longer talks to Zabbix at all once its board is on screen.
 */
class WidgetForm extends CWidgetForm
{
	public function addFields(): self
	{
		// The label and the three option captions come from the widget's OWN
		// catalogue, not from gettext. Zabbix's core catalogue happens to carry
		// "Normal" and nothing else of ours, so `_()` shipped a form that was
		// English on the outside and translated in the middle - and the ja_JP
		// clickthrough caught exactly that.
		return $this->addField(
			(new CWidgetFieldRadioButtonList('speed', WidgetTranslator::translate('form.speed.label'), [
				Speed::SLOW => WidgetTranslator::translate('form.speed.option.slow'),
				Speed::NORMAL => WidgetTranslator::translate('form.speed.option.normal'),
				Speed::FAST => WidgetTranslator::translate('form.speed.option.fast')
			]))->setDefault(Speed::NORMAL)
		);
	}
}
