<?php
use App\Modules\News\Models\NewsArticle;
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?><?= e($article->title_ar) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/news" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة للأخبار</a>
<a href="/news/<?= (int) $article->id ?>/edit" class="btn btn-outline"><i data-lucide="edit" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<?php
$catColor = NewsArticle::getCategoryColor($article->category ?? 'general');
$catLabel = $categories[$article->category ?? 'general'] ?? 'عام';
$isPublished = (int) $article->is_published;
?>

<!-- Cover Image -->
<?php if ($article->cover_image_path): ?>
<div class="card" style="margin-bottom:20px;overflow:hidden;">
    <img src="<?= e($article->cover_image_path) ?>" alt="<?= e($article->title_ar) ?>" style="width:100%;max-height:400px;object-fit:cover;display:block;">
</div>
<?php endif; ?>

<!-- Article Content -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:30px;">
        <!-- Meta -->
        <div style="display:flex;align-items:center;gap:10px;margin-bottom:15px;">
            <span style="display:inline-block;padding:3px 12px;border-radius:10px;font-size:12px;font-weight:600;background:<?= $catColor ?>15;color:<?= $catColor ?>;"><?= e($catLabel) ?></span>
            <?php if ($isPublished): ?>
            <span style="display:inline-block;padding:3px 12px;border-radius:10px;font-size:12px;font-weight:600;background:#D1FAE5;color:#10B981;">منشور</span>
            <?php else: ?>
            <span style="display:inline-block;padding:3px 12px;border-radius:10px;font-size:12px;font-weight:600;background:#F3F4F6;color:#6B7280;">مسودة</span>
            <?php endif; ?>
            <span style="font-size:12px;color:#9CA3AF;"><?= e($article->created_at ?? '') ?></span>
            <?php if ($article->published_at): ?>
            <span style="font-size:12px;color:#9CA3AF;">| نُشر: <?= e($article->published_at) ?></span>
            <?php endif; ?>
        </div>

        <!-- Title -->
        <h1 style="margin:0 0 20px;font-size:24px;font-weight:700;color:#1A1A2E;line-height:1.5;"><?= e($article->title_ar) ?></h1>

        <!-- Body -->
        <div style="font-size:15px;line-height:2;color:#374151;white-space:pre-wrap;"><?= e($article->body_ar) ?></div>
    </div>
</div>

<!-- Action Buttons -->
<div class="card" style="padding:20px;display:flex;gap:10px;">
    <form method="POST" action="/news/<?= (int) $article->id ?>/toggle-publish" style="display:inline;">
        <?= csrf_field() ?>
        <?php if ($isPublished): ?>
        <button type="submit" class="btn btn-outline" style="color:#F59E0B;border-color:#F59E0B;">
            <i data-lucide="eye-off" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> إلغاء النشر
        </button>
        <?php else: ?>
        <button type="submit" class="btn btn-primary" style="background:#10B981;">
            <i data-lucide="send" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> نشر الخبر
        </button>
        <?php endif; ?>
    </form>
    <a href="/news/<?= (int) $article->id ?>/edit" class="btn btn-outline">
        <i data-lucide="edit" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> تعديل
    </a>
</div>

<?php $__template->endSection(); ?>
