<?php
$escape = $this->plugin('escapeHtml');
$labelInfo = $this->setting('property_label_information');
?>
<?php foreach ($values as $term => $propertyData): ?>
    <div class="property">
        <h4>
        <?php if ($propertyData['alternate_label']): ?>
        <?php echo $escape($propertyData['alternate_label']); ?>
        <?php else: ?>
        <?php echo $escape($propertyData['property']->label()); ?>
        <?php endif; ?>
        <?php if ('term' === $labelInfo): ?>
        <span class="field-term">(<?php echo $escape($propertyData['property']->term()); ?>)</span>
        <?php elseif ('vocab' === $labelInfo): ?>
        <span class="field-term">(<?php echo $escape($propertyData['property']->vocabulary()->label()); ?>)</span>
        <?php endif; ?>
        </h4>
        <?php foreach ($propertyData['values'] as $value): ?>
            <?php
            $class = 'value';
            if ('resource' == $value->type()) {
                $valueResource = $value->valueResource();
                $class .= ' ' . $escape($valueResource->resourceName());
            } elseif ('uri' == $value->type()) {
                $class .= ' uri';
            }
            ?>
            <div class="<?php echo $class; ?>">
                <?php if ('resource' == $value->type() && $thumbnail = $valueResource->primaryMedia()): ?>
                    <img
                        src="<?php echo $escape($thumbnail->thumbnailUrl('square')); ?>"
                        title="<?php echo $escape($thumbnail->displayTitle()); ?>"
                        alt="<?php echo $escape($thumbnail->mediaType()); ?> thumbnail"
                    >
                <?php endif; ?>
                <?php if ($language = $value->lang()): ?>
                <span class="language"><?php echo $language; ?></span>
                <?php endif; ?>
                <?php echo $value->asHtml(); ?>
            </div>
        <?php endforeach; ?>
    </div>
<?php endforeach; ?>
