<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$item = $resource->item();
?>
<div class="resource-details" data-resource-values="<?php echo $escape($values); ?>">

    <?php if ($linkTitle): ?>
    <h3 class="o-title"><?php echo $resource->link($resource->displayTitle()); ?></h3>
    <?php else: ?>
    <h3 class="o-title"><?php echo $escape($resource->displayTitle()); ?></h3>
    <?php endif; ?>
    <div class="o-description"><?php echo $escape($resource->displayDescription()); ?></div>

    <?php echo $this->thumbnail($resource, 'square'); ?>

    <div class="meta-group">
        <h4><?php echo $translate('ID'); ?></h4>
        <div class="value"><?php echo $escape($resource->id()); ?></div>
    </div>

    <div class="meta-group">
        <h4><?php echo $translate('Part of Item'); ?></h4>
        <div class="value"><?php echo $item->link($item->displayTitle()); ?></div>
    </div>

    <?php if ($resourceClass = $resource->resourceClass()): ?>
    <div class="meta-group">
        <h4><?php echo $translate('Class'); ?></h4>
        <div class="value"><?php echo $escape($resourceClass->label()); ?></div>
    </div>
    <?php endif; ?>

    <?php if ($resourceTemplate = $resource->resourceTemplate()): ?>
    <div class="meta-group">
        <h4><?php echo $translate('Resource template'); ?></h4>
        <div class="value"><?php echo $resourceTemplate->link($resourceTemplate->label()); ?></div>
    </div>
    <?php endif; ?>

    <?php if ($resource->lang()): ?>
    <div class="meta-group">
        <h4><?php echo $translate('Language'); ?></h4>
        <div class="value"><?php echo $escape($resource->lang()); ?></div>
    </div>
    <?php endif; ?>

    <?php if ($resource->mediaType()): ?>
    <div class="meta-group">
        <h4><?php echo $translate('MIME type'); ?></h4>
        <div class="value"><?php echo $escape($resource->mediaType()); ?></div>
    </div>
    <?php endif; ?>

    <?php if (is_numeric($resource->size())): ?>
    <div class="meta-group">
        <h4><?php echo $translate('Size'); ?></h4>
        <div class="value"><?php echo sprintf($translate('%s bytes'), number_format($resource->size())); ?></div>
    </div>
    <?php endif; ?>

    <div class="meta-group">
        <h4><?php echo $escape($translate('Visibility')); ?></h4>
        <div class="value"><?php echo ($resource->isPublic()) ? $translate('Public') : $translate('Private'); ?></div>
    </div>

    <?php $sites = $item->sites(); ?>
    <?php if ($sites): ?>
    <div class="meta-group resource-sites">
        <h4><?php echo $translate('Sites'); ?></h4>
        <?php foreach ($sites as $site): ?>
        <div class="value">
            <?php
            $siteTitle = $site->title();
            $externalLinkText = sprintf($translate('View this media in "%s"'), $siteTitle);
            echo $site->link($siteTitle);
            echo $this->hyperlink('', $this->url('site/resource-id', ['site-slug' => $site->slug(), 'controller' => 'media', 'id' => $resource->id()]),
                ['class' => 'o-icon-external', 'target' => '_blank', 'aria-label' => $externalLinkText, 'title' => $externalLinkText]);
            ?>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <?php $this->trigger('view.details', array('entity' => $resource)); ?>
</div>
