<?php

use ChurchCRM\dto\SystemURLs;

$sPageTitle = 'Videos - ' . $churchName;
require SystemURLs::getDocumentRoot() . '/Include/HeaderNotLoggedIn.php';
$hidePageHeader = true;
require 'header.php';
?>

<div class="page-header">
  <div class="container animate-up">
    <h1><i class="fa-solid fa-video me-2"></i>Videos</h1>
    <p class="mb-0 opacity-75">Watch our latest videos and messages</p>
  </div>
</div>

<div class="container py-5">
  <?php if (empty($videos)): ?>
  <div class="text-center py-5 animate-on-scroll">
    <i class="fa-solid fa-video fa-4x text-secondary mb-3" style="opacity:.4;"></i>
    <h4>No Videos Yet</h4>
    <p class="text-secondary">Check back soon for new video content.</p>
  </div>
  <?php else: ?>
  <div class="row">
    <?php foreach ($videos as $i => $video): ?>
    <div class="col-lg-4 col-md-6 mb-4 animate-on-scroll" style="transition-delay: <?= ($i % 6) * .08 ?>s;">
      <div class="card video-card shadow-sm">
        <?php if ($video['vid_embed_code']): ?>
          <div class="ratio ratio-16x9"><?= $video['vid_embed_code'] ?></div>
        <?php elseif ($video['vid_thumbnail_url']): ?>
          <div class="overflow-hidden rounded-top">
            <img src="<?= $video['vid_thumbnail_url'] ?>" class="card-img-top" alt="<?= $video['vid_title'] ?>">
          </div>
        <?php else: ?>
          <div class="d-flex align-items-center justify-content-center bg-light" style="height:200px;">
            <i class="fa-solid fa-video fa-3x text-secondary" style="opacity:.4;"></i>
          </div>
        <?php endif; ?>
        <div class="card-body d-flex flex-column">
          <h5 class="card-title"><?= $video['vid_title'] ?></h5>
          <div class="text-secondary small mb-2">
            <i class="fa-solid fa-calendar me-1"></i><?= $video['vid_date'] ? date('F j, Y', strtotime($video['vid_date'])) : 'TBD' ?>
            <?= $video['vid_category'] ? " · $video[vid_category]" : '' ?>
          </div>
          <p class="card-text flex-grow-1"><?= substr($video['vid_description'], 0, 150) ?: '' ?></p>
          <?php if ($video['vid_url']): ?>
            <a href="<?= $video['vid_url'] ?>" target="_blank" class="btn btn-primary mt-auto">
              <i class="fa-solid fa-play me-1"></i>Watch Now
            </a>
          <?php endif; ?>
        </div>
      </div>
    </div>
    <?php endforeach; ?>
  </div>
  <?php endif; ?>
</div>

<?php require 'footer.php'; ?>
<?php require SystemURLs::getDocumentRoot() . '/Include/FooterNotLoggedIn.php'; ?>
