<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إعدادات النظام<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php if (empty($grouped)): ?>
    <div class="card" style="padding:40px;text-align:center;color:#6B7280;">
        <p>لا توجد إعدادات مسجلة بعد. ستظهر تلقائياً عند إضافة الوحدات.</p>
    </div>
<?php else: ?>
    <?php foreach ($grouped as $group => $settings): ?>
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
            <h3 style="margin:0;color:#1e3a5f;"><?= e($group) ?></h3>
            <?php if (can('settings.edit')): ?>
            <a href="/settings/group/<?= urlencode($group) ?>" class="btn btn-sm btn-outline">تعديل</a>
            <?php endif; ?>
        </div>
        <div class="table-responsive">
            <table class="data-table">
                <thead>
                    <tr>
                        <th>المفتاح</th>
                        <th>القيمة</th>
                        <th>النوع</th>
                        <th>الوصف</th>
                        <th>قابل للتعديل</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($settings as $s): ?>
                    <tr>
                        <td><code style="font-size:12px;"><?= e($s['config_key']) ?></code></td>
                        <td style="max-width:200px;overflow:hidden;text-overflow:ellipsis;"><?= e($s['config_value'] ?? '—') ?></td>
                        <td><span style="background:#F3F4F6;padding:2px 8px;border-radius:4px;font-size:12px;"><?= e($s['config_type']) ?></span></td>
                        <td style="color:#6B7280;font-size:13px;"><?= e($s['description_ar'] ?? '—') ?></td>
                        <td><?= $s['is_editable'] ? '<span style="color:#059669;">نعم</span>' : '<span style="color:#DC2626;">لا</span>' ?></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
    <?php endforeach; ?>
<?php endif; ?>
<?php $__template->endSection(); ?>