<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?><?= e($discipline->name_ar) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<?php if (can('sa.discipline.manage')): ?>
<a href="/sa/disciplines/<?= (int) $discipline->id ?>/edit" class="btn btn-outline"><i data-lucide="edit-3" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<?php endif; ?>
<a href="/sa/disciplines" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة للقائمة</a>
<?php $__template->endSection(); ?>

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

<?php
$allCategories = $categories ?? [];
$catLabel = $allCategories[$discipline->category ?? ''] ?? '—';
$isActive = (int) $discipline->is_active;
?>

<!-- Header Card -->
<div class="card" style="margin-bottom:20px;overflow:hidden;">
    <div style="padding:25px;display:flex;align-items:start;gap:20px;">
        <div style="width:72px;height:72px;border-radius:16px;background:#F3F4F6;display:flex;align-items:center;justify-content:center;flex-shrink:0;">
            <i data-lucide="<?= e($discipline->icon ?? 'activity') ?>" style="width:36px;height:36px;color:#0D7377;"></i>
        </div>
        <div style="flex:1;">
            <div style="display:flex;align-items:center;gap:12px;margin-bottom:8px;flex-wrap:wrap;">
                <h2 style="margin:0;font-size:22px;font-weight:700;color:#1A1A2E;"><?= e($discipline->name_ar) ?></h2>
                <?php if ($isActive): ?>
                <span style="background:#ECFDF5;color:#059669;font-size:12px;padding:4px 12px;border-radius:12px;font-weight:600;">فعّال</span>
                <?php else: ?>
                <span style="background:#FEE2E2;color:#DC2626;font-size:12px;padding:4px 12px;border-radius:12px;font-weight:600;">معطّل</span>
                <?php endif; ?>
            </div>
            <?php if ($discipline->name_en): ?>
            <div style="font-size:14px;color:#6B7280;margin-bottom:8px;"><?= e($discipline->name_en) ?></div>
            <?php endif; ?>
            <div style="display:flex;gap:12px;flex-wrap:wrap;font-size:13px;color:#6B7280;">
                <span style="display:inline-flex;align-items:center;gap:4px;">
                    <i data-lucide="tag" style="width:14px;height:14px;"></i>
                    <code style="font-size:11px;background:#F3F4F6;padding:1px 6px;border-radius:4px;"><?= e($discipline->code) ?></code>
                </span>
                <?php if ($discipline->category): ?>
                <span style="display:inline-flex;align-items:center;gap:4px;padding:2px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#F3F4F6;color:#4B5563;">
                    <?= e($catLabel) ?>
                </span>
                <?php endif; ?>
                <span style="display:inline-flex;align-items:center;gap:4px;">
                    <i data-lucide="arrow-up-down" style="width:14px;height:14px;"></i>
                    ترتيب: <?= (int) $discipline->sort_order ?>
                </span>
            </div>
            <?php if ($discipline->description_ar): ?>
            <p style="margin:12px 0 0;font-size:14px;color:#4B5563;line-height:1.7;"><?= e($discipline->description_ar) ?></p>
            <?php endif; ?>
        </div>
        <div style="flex-shrink:0;">
            <form method="POST" action="/sa/disciplines/<?= (int) $discipline->id ?>/toggle" style="display:inline;">
                <?= csrf_field() ?>
                <?php if ($isActive): ?>
                <button type="submit" class="btn btn-outline" style="color:#DC2626;border-color:#DC2626;" onclick="return confirm('هل أنت متأكد من إيقاف هذا النشاط؟')">
                    <i data-lucide="pause-circle" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> إيقاف
                </button>
                <?php else: ?>
                <button type="submit" class="btn btn-primary" onclick="return confirm('هل أنت متأكد من تفعيل هذا النشاط؟')">
                    <i data-lucide="play-circle" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> تفعيل
                </button>
                <?php endif; ?>
            </form>
        </div>
    </div>
</div>

<!-- Detail Fields -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
        <i data-lucide="info" style="width:18px;height:18px;color:#6B7280;"></i>
        <h3 style="margin:0;color:#6B7280;font-size:15px;">تفاصيل النشاط</h3>
    </div>
    <div style="padding:15px 20px;">
        <table style="width:100%;font-size:13px;">
            <tr>
                <td style="padding:8px 0;color:#6B7280;width:30%;">رقم السجل</td>
                <td style="padding:8px 0;font-weight:600;">#<?= (int) $discipline->id ?></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">الكود</td>
                <td style="padding:8px 0;"><code style="font-size:12px;background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($discipline->code) ?></code></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">الاسم بالعربي</td>
                <td style="padding:8px 0;font-weight:600;"><?= e($discipline->name_ar) ?></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">الاسم بالإنجليزي</td>
                <td style="padding:8px 0;"><?= e($discipline->name_en ?? '—') ?></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">التصنيف</td>
                <td style="padding:8px 0;"><?= e($catLabel) ?></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">الأيقونة</td>
                <td style="padding:8px 0;">
                    <span style="display:inline-flex;align-items:center;gap:6px;">
                        <i data-lucide="<?= e($discipline->icon ?? 'activity') ?>" style="width:18px;height:18px;color:#0D7377;"></i>
                        <?= e($discipline->icon ?? 'activity') ?>
                    </span>
                </td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">ترتيب العرض</td>
                <td style="padding:8px 0;"><?= (int) ($discipline->sort_order ?? 0) ?></td>
            </tr>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">الحالة</td>
                <td style="padding:8px 0;">
                    <?php if ($isActive): ?>
                    <span style="background:#ECFDF5;color:#059669;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;">فعّال</span>
                    <?php else: ?>
                    <span style="background:#FEE2E2;color:#DC2626;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;">معطّل</span>
                    <?php endif; ?>
                </td>
            </tr>
            <?php if ($discipline->description_ar): ?>
            <tr>
                <td style="padding:8px 0;color:#6B7280;vertical-align:top;">الوصف</td>
                <td style="padding:8px 0;line-height:1.7;"><?= e($discipline->description_ar) ?></td>
            </tr>
            <?php endif; ?>
            <?php if (isset($discipline->created_at) && $discipline->created_at): ?>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">تاريخ الإنشاء</td>
                <td style="padding:8px 0;"><?= e($discipline->created_at) ?></td>
            </tr>
            <?php endif; ?>
            <?php if (isset($discipline->updated_at) && $discipline->updated_at): ?>
            <tr>
                <td style="padding:8px 0;color:#6B7280;">آخر تحديث</td>
                <td style="padding:8px 0;"><?= e($discipline->updated_at) ?></td>
            </tr>
            <?php endif; ?>
        </table>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') {
        lucide.createIcons();
    }
});
</script>
<?php $__template->endSection(); ?>
