<?php

declare(strict_types=1);

require_once __DIR__ . '/helpers.php';

media_module_boot();

$newsRecord = find_news_post_or_abort((int) ($_GET['id'] ?? 0));
$pageTitle = 'View News';

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">News profile</p>
            <h2 class="h4 mb-0"><?php echo e($newsRecord['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-news.php?id=' . (int) $newsRecord['id'])); ?>">Edit</a>
            <a class="btn btn-outline-danger" href="<?php echo e(base_url('app/modules/media/delete-news.php?id=' . (int) $newsRecord['id'])); ?>">Delete</a>
        </div>
    </div>
    <div class="row g-3">
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-broadcast"></i>
                <div>
                    <h4>Status</h4>
                    <p><span class="badge <?php echo e(($newsRecord['status'] ?? '') === 'published' ? 'badge-soft-success' : 'text-bg-light'); ?>"><?php echo e(ucfirst((string) $newsRecord['status'])); ?></span></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-link-45deg"></i>
                <div>
                    <h4>Slug</h4>
                    <p><?php echo e($newsRecord['slug']); ?></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-tags"></i>
                <div>
                    <h4>Category</h4>
                    <p><span class="badge <?php echo e(news_category_badge_class((string) ($newsRecord['category'] ?? 'general'))); ?>"><?php echo e(news_category_label((string) ($newsRecord['category'] ?? 'general'))); ?></span></p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="feature-tile"><i class="bi bi-person-circle"></i>
                <div>
                    <h4>Author</h4>
                    <p><?php echo e($newsRecord['author_name'] ?: 'System'); ?></p>
                </div>
            </div>
        </div>
    </div>
</section>

<?php if (!empty($newsRecord['featured_image'])): ?>
    <section class="panel-card mb-4">
        <div class="panel-card-header mb-3">
            <div>
                <p class="eyebrow mb-1">Featured image</p>
                <h3 class="h5 mb-0">Post artwork</h3>
            </div>
        </div>
        <img class="img-fluid rounded-4" src="<?php echo e(base_url($newsRecord['featured_image'])); ?>" alt="<?php echo e($newsRecord['title']); ?>">
    </section>
<?php endif; ?>

<section class="panel-card">
    <div class="panel-card-header mb-3">
        <div>
            <p class="eyebrow mb-1">Content</p>
            <h3 class="h5 mb-0">News body</h3>
        </div>
    </div>
    <p class="mb-0"><?php echo nl2br(e($newsRecord['body'])); ?></p>
</section>
<?php require dirname(__DIR__, 2) . '/includes/footer.php'; ?>