<commit_before><?php
/** @var \WEEEOpen\Tarallo\User $user */
/** @var \WEEEOpen\Tarallo\Item $item */
/** @var string|null $add */
/** @var string|null $edit */
/** @var bool $recursion */
/** @var string $self */
$recursion = $recursion ?? false;
$features = $item->getFeatures();
$lostAt = $item->getLostAt();
$deletedAt = $item->getDeletedAt();

// Too much logic in a template, blah bla blah... this templates renders an Item in every respect,
// what would I gain by moving this logic outside and passing $works as a parameter? More code, scattering
// templates-related stuff around (Adapter and other classes don't care if items are working or broken!),
// duplicating information, increasing probability of introducing bugs?
$working = '';
if(isset($features['working'])) {
	$working = ' working ' . $this->e($features['working']->value);
}

$containsMore = count($item->getContent()) > 0;

// Until proven guilty, er, true
$adding = false;
$editing = false;
$target = false;

$nextItemParameters = ['recursion' => true];
if(isset($edit)) {
	$nextItemParameters['edit'] = $edit;
	$editing = true;
	if(strtolower($edit) === strtolower($item->getCode())) {
		$target = true;
	} else {
		$target = false;
	}
} else if(isset($add)) {
	$nextItemParameters['add'] = $add;
	$adding = true;
	if(strtolower($add) === strtolower($item->getCode())) {
		$target = true;
	} else {
		$target = false;
	}
}

$summary = \WEEEOpen\Tarallo\SSRv1\Summary\Summary::peel($item);
$summary = explode(', ', $summary);

$product = $item->getProduct();
if($product !== null) {
	$productName = $this->e($product->getBrand()) . ' ' . $this->e($product->getModel()) . rtrim(' ' . $this->e($product->getVariantOrEmpty()));
}

$code_rawurlencoded = rawurlencode($item->getCode());
$code_escaped = $this->e($item->getCode());
$here = rtrim($self, '/') . '/';
?>

<?php if(!$recursion): $this->insert('breadcrumbs', ['item' => $item]); endif; ?>
<article class="container item<?=$recursion ? '' : ' root'?><?=$working?><?=$editing && $target ? ' head editing' : ''?><?= $deletedAt === null ? '' : ' deleted' ?>"
		data-code="<?=$code_escaped?>">
	<header class="row">
		<h2 class="col-12" id="code-<?=$code_escaped?>"><?=$code_escaped?></h2>
		<?php if($deletedAt === null): ?>
            <?php if($item->getFeature('restrictions') !== null): ?>
                <div class="inline-alert alert-info" role="alert">ℹ️&nbsp;<?= (WEEEOpen\Tarallo\SSRv1\UltraFeature::fromFeature
                    ($item->getFeature('restrictions'), $lang ?? 'en'))->pvalue; ?></div>
            <?php endif; ?>
            <?php if($item->getFeature('check') !== null): ?>
                <div class="inline-alert alert-warning" role="alert">⚠️️&nbsp;<?= (WEEEOpen\Tarallo\SSRv1\UltraFeature::fromFeature
                    ($item->getFeature('check'), $lang ?? 'en'))->pvalue; ?></div>
            <?php endif; ?>
            <?php if($item->getFeature('todo') !== null): ?>
                <div class="inline-alert alert-info" role="alert">➡️️️&nbsp;<?= (WEEEOpen\Tarallo\SSRv1\UltraFeature::fromFeature
                    ($item->getFeature('todo'), $lang ?? 'en'))->pvalue; ?></div>
            <?php endif; ?>
		<?php else: ?>
			<div class="inline-alert alert-danger" role="alert">❌️️&nbsp;This item has been deleted on <?= $deletedAt->setTimezone(new DateTimeZone('Europe/Rome'))->format('Y-m-d') ?></div>
		<?php endif; ?>
		<?php if($lostAt !== null): ?>
            <div class="inline-alert alert-serious" role="alert">🏷️️️&nbsp;This item has been lost on <?= $lostAt->setTimezone(new DateTimeZone('Europe/Rome'))->format('Y-m-d') ?></div>
		<?php endif; ?>
	</header>

	<?php if(!$editing || !$target): ?>
        <section class="summary <?=$working?> open">
			<?php foreach($summary as $line): ?><span><?= $this->e($line) ?><span class="sep">, </span></span><?php endforeach ?>
        </section>

		<section class="features collapse" id="collapsible-features-<?=$this->e($item->getCode())?>">
			<?php $this->insert('features', ['features' => $features, 'product' => $item->getProduct() === null ? [] : $item->getProduct()->getFeatures()]) ?>
		</section>
	<?php else: ?>
		<?php if($item->getProduct() !== null): ?>
			<section class="product features">
				<?php
				$this->insert('features', ['features' => $item->getProduct()->getFeatures()]);
				?>
			</section>
		<?php endif ?>

		<section class="own features editing">
			<?php
			$this->insert('featuresEdit', ['features' => $item->getOwnFeatures()]);
			?>
		</section>

		<section class="addfeatures">
			<label>Feature:
				<select class="allfeatures">
				</select></label><button>Add</button>
		</section>
	<?php endif ?>

	<nav class="itembuttons row" data-for-item="<?=$this->e($item->getCode())?>">
		<?php if($editing && $target): ?>
			<button class="save">💾&nbsp;Save</button><button class="cancel">🔙&nbsp;Cancel</button><?php if(!$containsMore): ?><button class="lost">🏷&nbsp;Lost</button><button class="delete">❌&nbsp;Delete</button><?php endif ?>
		<?php elseif(!$adding && !$editing): ?>
			<?php if($deletedAt === null): ?>
				<a class="btn btn-outline-primary btn-sm col-6 col-sm-4 col-md-auto" role="button" href="<?= $here ?>add/<?= $code_rawurlencoded ?>?from=<?= rawurlencode($here) ?>">
					<i class="fa fa-plus-circle"></i>&nbsp;Add
				</a>
				<a class="btn btn-outline-primary btn-sm col-6 col-sm-4 col-md-auto" role="button" href="<?= $here ?>edit/<?= $code_rawurlencoded ?>?from=<?= rawurlencode($here) ?>">
					<i class="fa fa-cogs"></i>&nbsp;Edit
				</a>
				<a class="btn btn-outline-primary btn-sm col-6 col-sm-4 col-md-auto" role="button" href="/new/item?copy=<?= $code_rawurlencoded ?>">
					<i class="fa fa-object-group"></i>&nbsp;Copy
				</a>
				<a class="btn btn-outline-primary btn-sm col-6 col-sm-4 col-md-auto" role="button" href="#">
					<i class="fa fa-map-pin"></i>&nbsp;Move
				</a>
			<?php endif ?>
			<a class="btn btn-outline-primary btn-sm col-6 col-sm-4 col-md-auto" data-toggle="collapse" href="#collapsible-features-<?=$this->e($item->getCode())?>" role="button" aria-expanded="false" aria-controls="#collapsible-features-<?=$this->e($item->getCode())?>">
				<i class="fa fa-globe"></i>&nbsp;Details
			</a>
			<a class="btn btn-outline-primary btn-sm col-6 col-sm-4 col-md-auto" role="button" href="/item/<?= $code_rawurlencoded ?>/history">
				<i class="fa fa-search"></i>&nbsp;History
			</a>
			<?php if($product !== null): ?>
				<a class="btn btn-outline-primary btn-sm col-12 col-md-auto" role="button" href="/product/<?=rawurlencode($product->getBrand())?>/<?=rawurlencode($product->getModel())?>/<?=rawurlencode($product->getVariant())?>">
					<i class="fa fa-briefcase"></i>&nbsp;View <?= $this->e($productName) ?>
				</a>
			<?php endif ?>
		<?php endif ?>
	</nav>

	<section class="subitems">
		<?php
		if($adding && $target) {
			$empty = new \WEEEOpen\Tarallo\ItemIncomplete(null);
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('brand'));
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('model'));
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('variant'));
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('type'));
			$this->insert('newItem', ['recursion' => true, 'innerrecursion' => false, 'base' => $empty]);
		}<commit_msg>Improve buttons<commit_after><?php
/** @var \WEEEOpen\Tarallo\User $user */
/** @var \WEEEOpen\Tarallo\Item $item */
/** @var string|null $add */
/** @var string|null $edit */
/** @var bool $recursion */
/** @var string $self */
$recursion = $recursion ?? false;
$features = $item->getFeatures();
$lostAt = $item->getLostAt();
$deletedAt = $item->getDeletedAt();

// Too much logic in a template, blah bla blah... this templates renders an Item in every respect,
// what would I gain by moving this logic outside and passing $works as a parameter? More code, scattering
// templates-related stuff around (Adapter and other classes don't care if items are working or broken!),
// duplicating information, increasing probability of introducing bugs?
$working = '';
if(isset($features['working'])) {
	$working = ' working ' . $this->e($features['working']->value);
}

$containsMore = count($item->getContent()) > 0;

// Until proven guilty, er, true
$adding = false;
$editing = false;
$target = false;

$nextItemParameters = ['recursion' => true];
if(isset($edit)) {
	$nextItemParameters['edit'] = $edit;
	$editing = true;
	if(strtolower($edit) === strtolower($item->getCode())) {
		$target = true;
	} else {
		$target = false;
	}
} else if(isset($add)) {
	$nextItemParameters['add'] = $add;
	$adding = true;
	if(strtolower($add) === strtolower($item->getCode())) {
		$target = true;
	} else {
		$target = false;
	}
}

$summary = \WEEEOpen\Tarallo\SSRv1\Summary\Summary::peel($item);
$summary = explode(', ', $summary);

$product = $item->getProduct();
if($product !== null) {
	$productName = $this->e($product->getBrand()) . ' ' . $this->e($product->getModel()) . rtrim(' ' . $this->e($product->getVariantOrEmpty()));
}

$code_rawurlencoded = rawurlencode($item->getCode());
$code_escaped = $this->e($item->getCode());
$here = rtrim($self, '/') . '/';
?>

<?php if(!$recursion): $this->insert('breadcrumbs', ['item' => $item]); endif; ?>
<article class="container item<?=$recursion ? '' : ' root'?><?=$working?><?=$editing && $target ? ' head editing' : ''?><?= $deletedAt === null ? '' : ' deleted' ?>"
		data-code="<?=$code_escaped?>">
	<header class="row">
		<h2 class="col-12" id="code-<?=$code_escaped?>"><?=$code_escaped?></h2>
		<?php if($deletedAt === null): ?>
            <?php if($item->getFeature('restrictions') !== null): ?>
                <div class="inline-alert alert-info" role="alert">ℹ️&nbsp;<?= (WEEEOpen\Tarallo\SSRv1\UltraFeature::fromFeature
                    ($item->getFeature('restrictions'), $lang ?? 'en'))->pvalue; ?></div>
            <?php endif; ?>
            <?php if($item->getFeature('check') !== null): ?>
                <div class="inline-alert alert-warning" role="alert">⚠️️&nbsp;<?= (WEEEOpen\Tarallo\SSRv1\UltraFeature::fromFeature
                    ($item->getFeature('check'), $lang ?? 'en'))->pvalue; ?></div>
            <?php endif; ?>
            <?php if($item->getFeature('todo') !== null): ?>
                <div class="inline-alert alert-info" role="alert">➡️️️&nbsp;<?= (WEEEOpen\Tarallo\SSRv1\UltraFeature::fromFeature
                    ($item->getFeature('todo'), $lang ?? 'en'))->pvalue; ?></div>
            <?php endif; ?>
		<?php else: ?>
			<div class="inline-alert alert-danger" role="alert">❌️️&nbsp;This item has been deleted on <?= $deletedAt->setTimezone(new DateTimeZone('Europe/Rome'))->format('Y-m-d') ?></div>
		<?php endif; ?>
		<?php if($lostAt !== null): ?>
            <div class="inline-alert alert-serious" role="alert">🏷️️️&nbsp;This item has been lost on <?= $lostAt->setTimezone(new DateTimeZone('Europe/Rome'))->format('Y-m-d') ?></div>
		<?php endif; ?>
	</header>

	<?php if(!$editing || !$target): ?>
        <section class="summary <?=$working?> open">
			<?php foreach($summary as $line): ?><span><?= $this->e($line) ?><span class="sep">, </span></span><?php endforeach ?>
        </section>

		<section class="features collapse" id="collapsible-features-<?=$this->e($item->getCode())?>">
			<?php $this->insert('features', ['features' => $features, 'product' => $item->getProduct() === null ? [] : $item->getProduct()->getFeatures()]) ?>
		</section>
	<?php else: ?>
		<?php if($item->getProduct() !== null): ?>
			<section class="product features">
				<?php
				$this->insert('features', ['features' => $item->getProduct()->getFeatures()]);
				?>
			</section>
		<?php endif ?>

		<section class="own features editing">
			<?php
			$this->insert('featuresEdit', ['features' => $item->getOwnFeatures()]);
			?>
		</section>

		<section class="addfeatures">
			<label>Feature:
				<select class="allfeatures">
				</select></label><button>Add</button>
		</section>
	<?php endif ?>

	<nav class="itembuttons row mx-md-2" data-for-item="<?=$this->e($item->getCode())?>">
		<?php if($editing && $target): ?>
			<button class="save">💾&nbsp;Save</button><button class="cancel">🔙&nbsp;Cancel</button><?php if(!$containsMore): ?><button class="lost">🏷&nbsp;Lost</button><button class="delete">❌&nbsp;Delete</button><?php endif ?>
		<?php elseif(!$adding && !$editing): ?>
			<?php if($deletedAt === null): ?>
				<a class="btn btn-outline-primary btn-item col-6 col-sm-4 col-md-auto" role="button" href="<?= $here ?>add/<?= $code_rawurlencoded ?>?from=<?= rawurlencode($here) ?>">
					<i class="fa fa-plus-circle"></i>&nbsp;Add
				</a>
				<a class="btn btn-outline-primary btn-item col-6 col-sm-4 col-md-auto" role="button" href="<?= $here ?>edit/<?= $code_rawurlencoded ?>?from=<?= rawurlencode($here) ?>">
					<i class="fa fa-cogs"></i>&nbsp;Edit
				</a>
				<a class="btn btn-outline-primary btn-item col-6 col-sm-4 col-md-auto" role="button" href="/new/item?copy=<?= $code_rawurlencoded ?>">
					<i class="fa fa-object-group"></i>&nbsp;Copy
				</a>
				<a class="btn btn-outline-primary btn-item col-6 col-sm-4 col-md-auto" role="button" href="#">
					<i class="fa fa-map-pin"></i>&nbsp;Move
				</a>
			<?php endif ?>
			<a class="btn btn-outline-primary btn-item col-6 col-sm-4 col-md-auto" data-toggle="collapse" href="#collapsible-features-<?=$this->e($item->getCode())?>" role="button" aria-expanded="false" aria-controls="#collapsible-features-<?=$this->e($item->getCode())?>">
				<i class="fa fa-globe"></i>&nbsp;Details
			</a>
			<a class="btn btn-outline-primary btn-item col-6 col-sm-4 col-md-auto" role="button" href="/item/<?= $code_rawurlencoded ?>/history">
				<i class="fa fa-users"></i>&nbsp;History
			</a>
			<?php if($product !== null): ?>
				<a class="btn btn-outline-primary btn-item col-12 col-md-auto" role="button" href="/product/<?=rawurlencode($product->getBrand())?>/<?=rawurlencode($product->getModel())?>/<?=rawurlencode($product->getVariant())?>">
					<i class="fa fa-briefcase"></i>&nbsp;View <?= $this->e($productName) ?>
				</a>
			<?php endif ?>
		<?php endif ?>
	</nav>

	<section class="subitems">
		<?php
		if($adding && $target) {
			$empty = new \WEEEOpen\Tarallo\ItemIncomplete(null);
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('brand'));
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('model'));
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('variant'));
			$empty->addFeature(new \WEEEOpen\Tarallo\BaseFeature('type'));
			$this->insert('newItem', ['recursion' => true, 'innerrecursion' => false, 'base' => $empty]);
		}
{'fraction_non_alphanumeric': 0.2383533447684391, 'fraction_numerical': 0.0032246998284734133, 'mean_word_length': 4.32553891121666, 'pattern_counts': {'":': 0, '<': 277, '<?xml version=': 0, '>': 415, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '333726', 'n_tokens_mistral': 5347, 'n_tokens_neox': 5043, 'n_words': 958}