<?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 if (can('scheduling.manage_rules')): ?>
<a href="/scheduling/rules/create" class="btn btn-primary">إضافة قاعدة</a>
<?php endif; ?>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div class="card" style="padding:20px;">
    <?php if (empty($rules)): ?>
    <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>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($rules as $rule): ?>
            <tr>
                <td style="font-weight:600;"><?= e($rule['rule_name_ar'] ?? '') ?></td>
                <td><span style="font-size:12px;background:#EDE9FE;color:#7C3AED;padding:2px 8px;border-radius:4px;"><?= e($ruleTypes[$rule['rule_type']] ?? $rule['rule_type']) ?></span></td>
                <td style="font-size:13px;"><?= e($rule['applies_to'] ?? 'all') ?><?= $rule['applies_to_id'] ? ' #' . $rule['applies_to_id'] : '' ?></td>
                <td><?= (int) $rule['priority'] ?></td>
                <td>
                    <?php if ($rule['is_active']): ?>
                    <span style="color:#059669;font-size:12px;">● نشطة</span>
                    <?php else: ?>
                    <span style="color:#DC2626;font-size:12px;">● معطلة</span>
                    <?php endif; ?>
                </td>
                <td>
                    <form method="POST" action="/scheduling/rules/<?= (int) $rule['id'] ?>/toggle" style="display:inline;"><?= csrf_field() ?><button type="submit" class="btn btn-sm btn-outline"><?= $rule['is_active'] ? 'تعطيل' : 'تفعيل' ?></button></form>
                    <form method="POST" action="/scheduling/rules/<?= (int) $rule['id'] ?>/delete" style="display:inline;" onsubmit="return confirm('حذف القاعدة؟')"><?= csrf_field() ?><button type="submit" class="btn btn-sm btn-outline" style="color:#DC2626;">حذف</button></form>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <?php endif; ?>
</div>
<?php $__template->endSection(); ?>
