<?php
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'items show');
if ($owner = $item->owner()) {
    $ownerText = $escape($item->owner()->name());
} else {
    $ownerText = $this->translate('[no owner]');
}

$sectionNavs = [
    'item-metadata' => $this->translate('Metadata'),
    'item-linked' => $this->translate('Linked Resources'),
];
?>
<?php echo $this->pageTitle(sprintf($this->translate('Item: “%s”'), $item->displayTitle())); ?>
<div id="page-actions">
    <?php if ($item->userIsAllowed('update')): ?>
    <?php echo $item->link($this->translate('Edit item'), 'edit', ['class' => 'button']); ?>
    <?php endif; ?>
</div>

<?php echo $this->sectionNav($sectionNavs, 'view.show.section_nav', $item); ?>

<div id="item-metadata" class="active section">
    <?php if ( $item->resourceClass()): ?>
        <div class="meta-group">
            <h4><?php echo $this->translate('Class'); ?></h4>
            <div class="value"><?php echo $escape($item->resourceClass()->label()); ?></div>
        </div>
    <?php endif; ?>
    <?php echo $item->displayValues(); ?>
</div>

<div id="item-linked" class="section">
    <?php $subjects = $item->subjectValues(); ?>
    <?php $objects = $item->objectValues(); ?>
    <?php if ( $subjects || $objects ): ?>
        <?php echo $item->displayLinkedResources(); ?>
    <?php else: ?>
        <div class="no-resources">
            <p><?php echo $this->translate('There are no linked resources for this item.'); ?></p>
        </div>
    <?php endif; ?>
</div>


<div class="sidebar active">
    <?php if ($primaryMedia = $item->primaryMedia()): ?>
    <img 
        src="<?php echo $escape($primaryMedia->thumbnailUrl('square')); ?>" 
        title="<?php echo $escape($primaryMedia->displayTitle()); ?>" 
        alt="<?php echo $escape($primaryMedia->mediaType()); ?> thumbnail"
    >
    <?php endif; ?>
    <div class="meta-group">
        <h4><?php echo $this->translate('Visibility'); ?></h4>
        <div class="value"><?php echo ($item->isPublic()) ? $escape($this->translate('Public')) : $escape($this->translate('Private')); ?></div>
    </div>
    <?php $itemsets = $item->itemSets(); ?>
    <?php if (count($itemsets) > 0): ?>
    <div class="meta-group">
        <h4><?php echo $this->translate('Item Sets'); ?></h4>
        <?php foreach ($itemsets as $itemset): ?>
        <div class="value item-sets"><?php echo $itemset->link($itemset->displayTitle()); ?></div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>
    <div class="meta-group">
        <h4><?php echo $this->translate('Date Created'); ?></h4>
        <div class="value"><?php echo $escape($this->i18n()->dateFormat($item->created())); ?></div>
    </div>
    <div class="meta-group">
        <h4><?php echo $this->translate('Owner'); ?></h4>
        <div class="value"><?php echo $ownerText; ?></div>
    </div>
    <?php if ($item->media()): ?>
    <div class="meta-group">
        <h4><?php echo $this->translate('Media'); ?></h4>
        <?php foreach ($item->media() as $media): ?>
        <div class="value">
            <a href="<?php echo $media->url(); ?>">
                <img 
                    src="<?php echo $escape($media->thumbnailUrl('square')); ?>"
                title="<?php echo $escape($media->displayTitle()); ?>" 
                alt="<?php echo $escape($media->mediaType()); ?> thumbnail"
                >
                <span class="file-name"><?php echo $escape($media->displayTitle()); ?>
            </a>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>
</div>
<?php $this->trigger('view.show.after'); ?>
