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

<!-- Display a single tag object -->
<?php if ($content): ?>

<!-- Title and meta information -->
<div>
  <h2 class="title"><?php echo $content->icon; ?> <?php echo $content->escapeForXss('title'); ?></h2>
  <?php if ($contentInfo): ?>
  <p class="content-info">
    <span class="small">
    <?php if (TfSession::isAdmin()): ?>
    <a href="<?php echo TFISH_ADMIN_URL . 'admin.php?op=edit&amp;id=' . $content->escapeForXss('id'); ?>"><i title="<?php echo TFISH_EDIT_CONTENT; ?>" class="fas fa-edit"></i></a>
    <?php endif; ?>
    <?php echo $contentInfo; ?>
  </span>
  </p>
  <?php endif; ?>
</div>

<!-- Image -->
<?php if ($content->image): ?>
<div>
  <figure class="figure-centre">
  <img class="image img-fluid" src="<?php echo $content->getCachedImage(1170); ?>" 
  <?php if ($content->caption): ?>
      title="<?php echo $content->escapeForXss('caption'); ?>" alt="<?php echo $content->escapeForXss('caption'); ?>"/>
  <figcaption class="text-left"><em><?php echo $content->escapeForXss('caption'); ?></em></figcaption>
  <?php else: ?>
      alt="" />
  <?php endif; ?>
  </figure>
</div>
<?php endif; ?>

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

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

<!-- Display parent work -->
<?php if (!empty($parent)): ?>
<div class="clearfix">
  <div>
    <h3 class="mb-3"><?php echo TFISH_RELATED; ?></h3>
    <h4 class="parent"><a href="<?php echo $parent->getUrl($targetFileName); ?>"><?php echo $parent->icon; ?> <?php echo $parent->escapeForXss('title'); ?></a></h4>
    <?php if ($parent->image): ?>
    <div class="float-left">
      <figure class="figure-left">
      <a href="<?php echo $parent->getUrl($targetFileName); ?>">
      <img class="image img-fluid" src="<?php echo $parent->getCachedImage(150); ?>" 
      <?php if ($parent->caption): ?>
          title="<?php echo $parent->escapeForXss('caption'); ?>" alt="<?php echo $parent->escapeForXss('caption'); ?>"
      <?php else: ?>
          alt=""
      <?php endif; ?>
      /></a>
      </figure>
    </div>
    <?php endif; ?>
    <div class="teaser">
      <?php echo $parent->escapeForXss('teaser'); ?>
    </div>
  </div>
</div>
<?php endif; ?>

<!-- Display other works linked to this tag -->    
<?php if (!empty($firstChildren)): ?>
<?php if (isset($collectionPagination)): ?>
<div class="d-flex justify-content-end collection-pagination-top clearfix">
  <?php echo $collectionPagination; ?>
</div>
<?php endif; ?>
<div>
  <h3 class="mb-3">In this collection</h3>
</div>
<div>
  <?php foreach ($firstChildren as $child): ?>
  <div class="clearfix">
    <h4 class="child-title"><a href="<?php echo $child->getUrl($targetFileName); ?>"><?php echo $child->icon; ?> <?php echo $child->escapeForXss('title'); ?></a></h4>
    <?php if ($child->image): ?>
    <div class="float-left">
      <figure class="figure-left">
      <a href="<?php echo $child->getUrl($targetFileName); ?>">
      <img class="image img-fluid" src="<?php echo $child->getCachedImage(150); ?>" 
      <?php if ($child->caption): ?>
          title="<?php echo $child->escapeForXss('caption'); ?>" alt="<?php echo $child->escapeForXss('caption'); ?>"
      <?php else: ?>
          alt=""
      <?php endif; ?>
      /></a>
      </figure>
    </div>
    <?php endif; ?>
    <div class="child-teaser">
      <?php echo $child->escapeForXss('teaser'); ?>
    </div>
  </div>
    <?php endforeach; ?>    
</div>

<!-- Intra-collection pagination -->
<?php if (isset($collectionPagination)): ?>
<div class="d-flex justify-content-end collection-pagination-bottom clearfix">
  <?php echo $collectionPagination; ?>
</div>
<?php endif; ?>
<?php endif; ?>

<?php endif; ?>