<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>الخصومات الخاصة<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<?php if (can('pricing.special_discounts.create')): ?>
<a href="/pricing/special-discounts/create" class="btn btn-primary">
    <i data-lucide="plus" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> إضافة خصم جديد
</a>
<?php endif; ?>
<a href="/pricing" 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'); ?>

<!-- Search -->
<div class="card" style="margin-bottom:15px;padding:15px;">
    <form method="GET" action="/pricing/special-discounts" style="display:flex;gap:10px;align-items:end;">
        <div class="form-group" style="flex:1;">
            <label class="form-label">بحث</label>
            <input type="text" name="q" value="<?= e($filters['search'] ?? '') ?>" class="form-input" placeholder="اسم الخصم...">
        </div>
        <button type="submit" class="btn btn-primary" style="padding:8px 20px;">
            <i data-lucide="search" style="width:14px;height:14px;vertical-align:middle;"></i> بحث
        </button>
    </form>
</div>

<!-- Table -->
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
        <i data-lucide="percent" style="width:18px;height:18px;color:#1e3a5f;"></i>
        <h3 style="margin:0;color:#1e3a5f;font-size:15px;">قائمة الخصومات الخاصة</h3>
    </div>
    <?php if (!empty($rows)): ?>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>#</th>
                    <th>اسم الخصم</th>
                    <th>النسبة</th>
                    <th>يحتاج إثبات</th>
                    <th>الحالة</th>
                    <th>الوصف</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $row): ?>
                <tr>
                    <td><?= (int) $row['id'] ?></td>
                    <td style="font-weight:600;"><?= e($row['name_ar']) ?></td>
                    <td style="font-weight:700;color:#1e3a5f;"><?= e($row['discount_percentage']) ?>%</td>
                    <td>
                        <?php if ($row['requires_document']): ?>
                            <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#FFF7ED;color:#D97706;">
                                <i data-lucide="file-check" style="width:12px;height:12px;vertical-align:middle;margin-left:3px;"></i> مطلوب
                            </span>
                        <?php else: ?>
                            <span style="color:#9CA3AF;font-size:12px;">غير مطلوب</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if ($row['is_active']): ?>
                            <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#ECFDF5;color:#059669;">فعال</span>
                        <?php else: ?>
                            <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#F3F4F6;color:#6B7280;">معطل</span>
                        <?php endif; ?>
                    </td>
                    <td style="font-size:12px;color:#6B7280;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"><?= e($row['description'] ?? '—') ?></td>
                    <td style="white-space:nowrap;">
                        <a href="/pricing/special-discounts/<?= (int) $row['id'] ?>/edit" class="btn btn-sm btn-outline" style="font-size:12px;padding:4px 10px;">
                            <i data-lucide="edit" style="width:12px;height:12px;vertical-align:middle;"></i> تعديل
                        </a>
                        <form method="POST" action="/pricing/special-discounts/<?= (int) $row['id'] ?>/toggle" style="display:inline;">
                            <?= csrf_field() ?>
                            <button type="submit" class="btn btn-sm btn-outline" style="font-size:12px;padding:4px 10px;<?= $row['is_active'] ? 'color:#DC2626;' : 'color:#059669;' ?>">
                                <?= $row['is_active'] ? 'تعطيل' : 'تفعيل' ?>
                            </button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if (!empty($pagination) && $pagination['last_page'] > 1): ?>
    <div style="padding:15px 20px;border-top:1px solid #E5E7EB;text-align:center;">
        <?php for ($i = 1; $i <= $pagination['last_page']; $i++): ?>
            <?php if ($i == $pagination['current_page']): ?>
                <span style="display:inline-block;padding:4px 12px;background:#1e3a5f;color:#fff;border-radius:4px;font-size:13px;margin:0 2px;"><?= $i ?></span>
            <?php else: ?>
                <a href="?page=<?= $i ?>&q=<?= urlencode($filters['search'] ?? '') ?>" style="display:inline-block;padding:4px 12px;color:#1e3a5f;text-decoration:none;font-size:13px;margin:0 2px;"><?= $i ?></a>
            <?php endif; ?>
        <?php endfor; ?>
    </div>
    <?php endif; ?>
    <?php else: ?>
    <div style="padding:60px 20px;text-align:center;">
        <div style="margin-bottom:15px;"><i data-lucide="percent" style="width:48px;height:48px;color:#D1D5DB;"></i></div>
        <h3 style="color:#6B7280;margin:0 0 8px;">لا توجد خصومات خاصة</h3>
        <p style="color:#9CA3AF;font-size:14px;margin:0 0 15px;">أضف أنواع الخصومات الخاصة (مثل: عضو شباب ورياضة) لتطبيقها على الأعضاء.</p>
        <a href="/pricing/special-discounts/create" class="btn btn-primary">إضافة خصم جديد</a>
    </div>
    <?php endif; ?>
</div>

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