<?php $__template->layout('Layout.main'); ?>

<?php $__template->section('title'); ?>مراكز التكلفة<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/accounting/cost-centers/create" class="btn btn-primary">+ مركز تكلفة جديد</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table" style="width:100%;">
            <thead>
                <tr>
                    <th>الكود</th>
                    <th>الاسم</th>
                    <th>النوع</th>
                    <th>الفرع</th>
                    <th>الحالة</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
                $branchMap = [];
                foreach ($branches as $b) $branchMap[(int)$b['id']] = $b['name_ar'];
                ?>
                <?php foreach ($centers as $cc): ?>
                    <tr>
                        <td style="font-weight:600;direction:ltr;text-align:right;"><?= e($cc['code']) ?></td>
                        <td><?= e($cc['name_ar']) ?></td>
                        <td><?= $cc['type'] === 'cost_center' ? 'مركز تكلفة' : 'مركز ربحية' ?></td>
                        <td><?= e($branchMap[(int)($cc['branch_id'] ?? 0)] ?? '—') ?></td>
                        <td><span style="color:<?= (int)$cc['is_active'] ? '#059669' : '#DC2626' ?>;"><?= (int)$cc['is_active'] ? 'نشط' : 'موقف' ?></span></td>
                        <td><a href="/accounting/cost-centers/<?= (int)$cc['id'] ?>/edit" class="btn btn-sm btn-outline">تعديل</a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($centers)): ?>
                    <tr><td colspan="6" style="text-align:center;color:#6B7280;padding:30px;">لا توجد مراكز تكلفة</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
