<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$thumbnail = $this->plugin('thumbnail');

$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;

$this->htmlElement('body')->appendAttribute('class', 'item-set resource browse');
?>

<?php echo $this->pageTitle($translate('Item sets'), 2); ?>

<?php echo $this->searchFilters(); ?>

<div class="browse-controls">
    <?php echo $this->pagination(); ?>
    <?php echo $this->hyperlink($translate('Advanced search'), $this->url(null, ['action' => 'search'], true), ['class' => 'advanced-search']); ?>
</div>

<?php $this->trigger('view.browse.before'); ?>
<ul class="resource-list">
<?php
$headingTerm = $this->siteSetting('browse_heading_property_term');
$bodyTerm = $this->siteSetting('browse_body_property_term');
foreach ($itemSets as $itemSet):
    $heading = $headingTerm ? $itemSet->value($headingTerm, ['default' => $translate('[Untitled]'), 'lang' => $valueLang]) : $itemSet->displayTitle(null, $valueLang);
    $body = $bodyTerm ? $itemSet->value($bodyTerm, ['lang' => $valueLang]) : $itemSet->displayDescription(null, $valueLang);
?>
    <li class="item-set resource">
        <?php
        $linkContent = sprintf('%s<span class="resource-name">%s</span>',
            $thumbnail($itemSet, 'medium'),
            $escape($heading));
        echo $itemSet->linkRaw($linkContent, null, ['class' => 'resource-link']);
        ?>
        <?php if ($body): ?>
        <div class="description"><?php echo $escape($body); ?></div>
        <?php endif; ?>
    </li>
<?php endforeach; ?>
</ul>
<?php $this->trigger('view.browse.after'); ?>
<?php echo $this->pagination(); ?>
