<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>التعارضات<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/scheduling" class="btn btn-outline">لوحة الجدولة</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<!-- Filter Tabs -->
<div class="card" style="margin-bottom:20px;padding:0;">
    <div style="display:flex;gap:0;border-bottom:2px solid #E5E7EB;">
        <?php foreach (['pending' => 'معلقة', 'resolved' => 'تم حلها', 'ignored' => 'تم تجاهلها', 'all' => 'الكل'] as $key => $label): ?>
        <a href="/scheduling/conflicts?status=<?= $key ?>" style="padding:12px 20px;font-size:14px;font-weight:600;text-decoration:none;border-bottom:3px solid <?= $filter === $key ? '#1e3a5f' : 'transparent' ?>;color:<?= $filter === $key ? '#1e3a5f' : '#6B7280' ?>;">
            <?= $label ?>
        </a>
        <?php endforeach; ?>
    </div>
</div>

<div class="card" style="padding:20px;">
    <?php if (empty($conflicts)): ?>
    <p style="color:#6B7280;text-align:center;padding:30px;">لا توجد تعارضات</p>
    <?php else: ?>
    <table class="table">
        <thead>
            <tr>
                <th>الشدة</th>
                <th>النوع</th>
                <th>الوصف</th>
                <th>التاريخ</th>
                <th>الوقت</th>
                <th>الحالة</th>
                <th>إجراء</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($conflicts as $c): ?>
            <tr>
                <td>
                    <span style="font-size:11px;padding:2px 8px;border-radius:4px;background:<?= $c['severity'] === 'error' ? '#FEE2E2' : '#FEF3C7' ?>;color:<?= $c['severity'] === 'error' ? '#DC2626' : '#D97706' ?>;">
                        <?= $c['severity'] === 'error' ? 'خطأ' : 'تحذير' ?>
                    </span>
                </td>
                <td style="font-size:13px;"><?= e($c['conflict_type'] ?? '') ?></td>
                <td style="font-size:13px;"><?= e($c['description_ar'] ?? '') ?></td>
                <td style="font-size:13px;"><?= e($c['conflict_date'] ?? '') ?></td>
                <td style="font-size:12px;direction:ltr;"><?= e(substr($c['conflict_time_start'] ?? '', 0, 5)) ?>-<?= e(substr($c['conflict_time_end'] ?? '', 0, 5)) ?></td>
                <td>
                    <?php if ($c['resolution'] === 'pending'): ?>
                    <span style="color:#F59E0B;">● معلق</span>
                    <?php elseif ($c['resolution'] === 'resolved'): ?>
                    <span style="color:#059669;">● تم الحل</span>
                    <?php else: ?>
                    <span style="color:#6B7280;">● تم التجاهل</span>
                    <?php endif; ?>
                </td>
                <td>
                    <?php if ($c['resolution'] === 'pending'): ?>
                    <form method="POST" action="/scheduling/conflicts/<?= (int) $c['id'] ?>/resolve" style="display:inline;">
                        <?= csrf_field() ?>
                        <input type="hidden" name="resolution" value="resolved">
                        <button type="submit" class="btn btn-sm btn-primary">حل</button>
                    </form>
                    <form method="POST" action="/scheduling/conflicts/<?= (int) $c['id'] ?>/resolve" style="display:inline;">
                        <?= csrf_field() ?>
                        <input type="hidden" name="resolution" value="ignored">
                        <button type="submit" class="btn btn-sm btn-outline">تجاهل</button>
                    </form>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <?php endif; ?>
</div>
<?php $__template->endSection(); ?>
