<?php
	declare(strict_types=1);
	/** @var FreshRSS_View $this */

	if ($this->tag === null) {
		throw new FreshRSS_Context_Exception('Tag not initialised!');
	}

	$ajax = Minz_Request::paramBoolean('ajax') || $this->displaySlider;
	$from = $ajax ? ($this->cfrom ?: Minz_Request::paramString('from')) : 'update';
?>
<div class="post">
	<h2>
		<?= $this->tag->name() ?>
	</h2>

	<div>
		<a href="<?= _url('index', 'index', 'get', 't_' . $this->tag->id()) ?>"><?= _i('link') ?> <?= _t('gen.action.filter') ?></a>
	</div>

	<form method="post" action="<?= _url('tag', 'update', 'id', $this->tag->id(), 'from', $from, ...($ajax ? ['#', 'slider'] : [])) ?>" autocomplete="off" data-auto-leave-validation="1">
		<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />

		<fieldset>
			<legend><?= _t('sub.category.information') ?></legend>
			<div class="form-group">
				<label class="group-name" for="name"><?= _t('sub.tag.name') ?></label>
				<div class="group-controls">
					<input type="text" name="name" id="name" value="<?= $this->tag->name() ?>" />
				</div>
			</div>

			<div class="form-group form-actions">
				<div class="group-controls">
					<button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button>
					<button type="reset" class="btn"><?= _t('gen.action.cancel') ?></button>
				</div>
			</div>
		</fieldset>

		<fieldset>
			<legend><?= _t('sub.feed.filteractions') ?></legend>
			<div class="form-group">
				<label class="group-name" for="filteractions_label"><?= _t('sub.tag.auto_label') ?></label>
				<div class="group-controls">
					<textarea name="filteractions_label" id="filteractions_label" class="w100"><?php
						foreach ($this->tag->filtersAction('label') as $filterRead) {
							echo htmlspecialchars($filterRead->toString(expandUserQueries: false), ENT_NOQUOTES, 'UTF-8') . PHP_EOL;
						}
					?></textarea>
					<p class="help"><?= _i('help') ?> <?= _t('sub.feed.filteractions.help') ?></p>
				</div>
			</div>
		</fieldset>

		<div class="form-group form-actions">
			<div class="group-controls">
				<button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button>
				<button type="reset" class="btn"><?= _t('gen.action.cancel') ?></button>
			</div>
		</div>
	</form>

	<h3><?= _t('sub.title.delete_label') ?></h3>
	<form method="post" action="<?= _url('tag', 'delete', 'id_tag', $this->tag->id()) ?>">
		<input type="hidden" name="_csrf" value="<?= FreshRSS_Auth::csrfToken() ?>" />
		<div class="form-group form-actions">
			<div class="group-controls">
				<button type="submit" class="btn btn-attention confirm"><?= _t('gen.action.remove') ?></button>
			</div>
		</div>
	</form>
</div>
