<?php declare(strict_types=1); ?>

<!-- Display a single collection object -->
<?php $content = $viewModel->content(); ?>
<?php $contentTags = $viewModel->contentTags(); ?>
<?php $parent = $viewModel->parent(); ?>
<?php $children = $viewModel->children(); ?>

<!-- Container -->
<div class="container">

<!-- Title and meta information -->
<div>
  <?php if ($content->media()): ?>
  <h2 class="title">
    <a href="<?php echo TFISH_URL . 'enclosure/?id=' . xss($content->id()); ?>"><?php echo xss($content->title()); ?></a>
  </h2>
  <?php else: ?>
  <h2 class="title"><?php echo xss($content->title()); ?></h2>
  <?php endif; ?>
  <p class="content-info">
    <span class="small">
      <a href="<?php echo TFISH_URL . 'rss/?id=' . $content->id(); ?>"><i class="fas fa-rss"></i></a>
      <?php echo xss($content->date()->format($viewModel->dateFormat())); ?>
      <?php echo ' | ' . xss($content->info()); ?>
      <?php if ($contentTags) {
          echo ' | ';
          $tags = [];
          foreach ($contentTags as $key => $value) {
            $tags[] = '<a href="?id=' . xss($key) . '">' . xss($value) . '</a>';
          }
          echo \implode(', ', $tags);
        } ?>
    </span>
  </p>
</div>

<!-- Image -->
<?php if ($content->image()): ?>
<div>
  <figure class="float-end figure-right">
    <img class="image img-fluid" srcset="<?php echo $content->cachedImage(400); ?> 400w, <?php echo $content->cachedImage(200); ?> 200w"
        sizes="(max-width: 767px) 200px, 400px"
        src="<?php echo $content->cachedImage(400); ?>" 
      <?php if ($content->caption()): ?>
        title="<?php echo xss($content->caption()); ?>" alt="<?php echo xss($content->caption()); ?>"/>
        <figcaption><em><?php echo xss($content->caption()); ?></em></figcaption>
      <?php else: ?>
        alt="" />
      <?php endif; ?>
  </figure>
</div>
<?php endif; ?>

<!-- Description -->
<div class="description">
  <?php if ($content->description()) echo $content->descriptionForDisplay(); ?>
</div>

<!-- Media attachment -->
<?php if ($content->media()): ?>
<div>
  <p class="media"><b><a href="<?php echo TFISH_URL . 'enclosure/?id=' . xss($content->id()); ?>"><i title="<?php echo TFISH_DOWNLOAD; ?>" class="fas fa-download"></i> <?php echo xss($content->media()); ?></a></b></p>
</div>
<?php endif; ?>

<!-- Rights -->
<?php if ($content->rights()): ?>
<div>
  <p class="rights"><em><?php echo xss($content->listRights()[$content->rights()]); ?></em></p>
</div>
<?php endif; ?>

<?php if (!empty($parent)) include_once('parent.html'); ?>
<?php if (!empty($children)) include_once('children-compact.html'); ?>

<!-- /.container -->
</div>
