<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

media_module_boot();

$mediaRecord = find_media_item_or_abort((int) ($_GET['id'] ?? 0));
$pageTitle = 'View Media';

require dirname(__DIR__, 2) . '/includes/header.php';
require dirname(__DIR__, 2) . '/includes/sidebar.php';
require dirname(__DIR__, 2) . '/includes/topbar.php';
require dirname(__DIR__, 2) . '/includes/flash.php';
?>
<section class="panel-card mb-4">
    <div class="panel-card-header mb-3">
        <div>
            <p class="eyebrow mb-1">Gallery record</p>
            <h2 class="h4 mb-0"><?php echo e($mediaRecord['title']); ?></h2>
        </div>
        <div class="d-flex gap-2">
            <a class="btn btn-outline-jlfc" href="<?php echo e(base_url('app/modules/media/edit-gallery.php?id=' . (int) $mediaRecord['id'])); ?>">Edit</a>
            <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/media/delete-gallery.php?id=' . (int) $mediaRecord['id'])); ?>">Delete</a>
        </div>
    </div>
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-camera-reels"></i>
                <div>
                    <h4>Type</h4>
                    <p><?php echo e(ucfirst((string) $mediaRecord['media_type'])); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-calendar-event"></i>
                <div>
                    <h4>Fixture</h4>
                    <p><?php echo e($mediaRecord['fixture_id'] ? (($mediaRecord['home_club_name'] ?? '') . ' vs ' . ($mediaRecord['away_club_name'] ?? '')) : 'None linked'); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-building"></i>
                <div>
                    <h4>Club</h4>
                    <p><?php echo e($mediaRecord['club_name'] ?: 'None linked'); ?></p>
                </div>
            </div>
        </div>
    </div>
    <?php if (($mediaRecord['media_type'] ?? '') === 'video'): ?>
        <video class="w-100 rounded-4" controls src="<?php echo e(base_url($mediaRecord['file_path'])); ?>"></video>
    <?php else: ?>
        <img class="img-fluid rounded-4" src="<?php echo e(base_url($mediaRecord['file_path'])); ?>" alt="<?php echo e($mediaRecord['title']); ?>">
    <?php endif; ?>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>