<?php
$cssClasses = array(
  'photo-text-wrapper',
  'photo-text-wrapper_'.$this->id,
  $this->class,
);
if ($this->textPosition) {
    $cssClasses[] = $this->textPosition;
}
if ($this->valign) {
    $cssClasses[] = $this->valign;
}
if ($this->valignCenter) {
    $cssClasses[] = '-valign-center';
}
$imageFiles = array();
$videoFiles = array();
if (is_array($this->backgroundImage)) {
  foreach (\FilesModel::findMultipleByUuids($this->backgroundImage) as $file) {
    if (in_array(
      $file->extension,
      array_map('trim', explode(',', \Config::get('validImageTypes')))
    )) {
      $imageFiles[] = $file;
    }
    else {
      $videoFiles[] = $file;
    }
  }
}
$imgColStyle = '';
if (count($imageFiles) && $image = $this->getImageObject($imageFiles[0]->uuid, $this->backgroundImageSize)) {
  $imgColStyle .= 'background-image: url("' . $image->src . '");';
}
if ((count($imageFiles) || count($videoFiles)) && $this->backgroundSize) {
  $imgColStyle .= 'background-size: ' . $this->backgroundSize . ';';
}
if ((count($imageFiles) || count($videoFiles)) && $this->backgroundPosition) {
  $imgColStyle .= 'background-position: ' . $this->backgroundPosition . ';';
}

$style = '';
if (!count($videoFiles) && !count($imageFiles)) {
  $style .= $imgColStyle;
}

?>

<?php $this->block('content'); ?>
<div class="<?php echo implode(' ', $cssClasses) ?> block"<?= $this->cssID ?><?php if ($this->style): ?> style="<?= $this->style ?>"<?php endif; ?>>

  <div class="photo-wall">
  <?php if (count($videoFiles)): ?>
    <div class="photo-wall-content">
      <video class="no-mejs" autoplay loop <?php if (count($imageFiles) && $image = $this->getImageObject($imageFiles[0]->uuid, $this->backgroundImageSize)): ?> poster="<?php echo $image->src ?>"<?php endif ?>>
        <?php foreach ($videoFiles as $video): ?>
          <source src="<?php echo TL_FILES_URL . $video->path ?>" type="video/<?php echo $video->extension ?>">
        <?php endforeach ?>
        <?php if (count($imageFiles) && $image = $this->getImageObject($imageFiles[0]->uuid, $this->backgroundImageSize)): ?>
          <?php $this->insert('picture_default', $image->picture) ?>
        <?php endif ?>
      </video>
    </div>
  <?php elseif (count($imageFiles) && $image = $this->getImageObject($imageFiles[0]->uuid, $this->backgroundImageSize)): ?>
    <div class="photo-wall-content" style="<?php echo htmlspecialchars($imgColStyle) ?>" data-image-url="<?php echo $image->src ?>"></div>
  <?php endif ?>
  </div>

  <div class="text-wall"><div class="text-wall-content<?php if ($this->padding): ?> <?= $this->padding ?><?php endif; ?>">
<?php $this->endblock(); ?>
