<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إدارة الفروع<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/branches/create" class="btn btn-primary">+ فرع جديد</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>كود الفرع</th>
                    <th>الاسم (عربي)</th>
                    <th>الاسم (إنجليزي)</th>
                    <th>الهاتف</th>
                    <th>المدير</th>
                    <th>الموظفون</th>
                    <th>الحالة</th>
                    <th>الإجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($branches as $b): ?>
                <tr>
                    <td><code><?= e($b['branch_code']) ?></code></td>
                    <td><?= e($b['name_ar']) ?></td>
                    <td><?= e($b['name_en'] ?? '—') ?></td>
                    <td><?= e($b['phone'] ?? '—') ?></td>
                    <td><?= e($b['manager_name'] ?? '—') ?></td>
                    <td><?= (int) $b['emp_count'] ?></td>
                    <td>
                        <?php if ($b['is_active']): ?>
                            <span style="color:#059669;font-weight:600;">● نشط</span>
                        <?php else: ?>
                            <span style="color:#DC2626;font-weight:600;">● معطل</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <div style="display:flex;gap:5px;">
                            <a href="/branches/<?= (int) $b['id'] ?>" class="btn btn-sm btn-outline">عرض</a>
                            <a href="/branches/<?= (int) $b['id'] ?>/edit" class="btn btn-sm btn-outline">تعديل</a>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php if (empty($branches)): ?>
                <tr><td colspan="8" style="text-align:center;padding:40px;color:#6B7280;">لا توجد فروع</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>