<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>هيكل الرواتب: <?= e($structure->name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<?php if (can('hr.employee.manage_salary')): ?>
<a href="/hr/salary-structures/<?= (int) $structure->id ?>/edit" class="btn btn-primary">تعديل</a>
<?php endif; ?>
<a href="/hr/salary-structures" class="btn btn-secondary">رجوع</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;">
        <div><span style="color:#6B7280;font-size:13px;">الكود</span><div style="font-weight:600;"><?= e($structure->code) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">الاسم</span><div><?= e($structure->name_ar) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">عدد الموظفين</span><div><?= $employeeCount ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">افتراضي</span><div><?= $structure->is_default ? 'نعم' : 'لا' ?></div></div>
    </div>
</div>

<?php if (!empty($earnings)): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;color:#059669;">الاستحقاقات (<?= count($earnings) ?>)</h3></div>
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>الكود</th><th>المكون</th><th>طريقة الحساب</th><th>المبلغ الافتراضي</th><th>خاضع للضريبة</th><th>خاضع للتأمين</th></tr></thead>
            <tbody>
                <?php foreach ($earnings as $e): ?>
                <tr>
                    <td><code><?= e($e['component_code']) ?></code></td>
                    <td><?= e($e['name_ar']) ?></td>
                    <td><?= e($e['calculation_type']) ?></td>
                    <td><?= number_format((float) $e['default_amount'], 2) ?></td>
                    <td><?= $e['is_taxable'] ? '&#10003;' : '-' ?></td>
                    <td><?= $e['is_insurable'] ? '&#10003;' : '-' ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>

<?php if (!empty($deductions)): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;color:#DC2626;">الخصومات (<?= count($deductions) ?>)</h3></div>
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>الكود</th><th>المكون</th><th>طريقة الحساب</th><th>المبلغ الافتراضي</th></tr></thead>
            <tbody>
                <?php foreach ($deductions as $d): ?>
                <tr>
                    <td><code><?= e($d['component_code']) ?></code></td>
                    <td><?= e($d['name_ar']) ?></td>
                    <td><?= e($d['calculation_type']) ?></td>
                    <td><?= number_format((float) $d['default_amount'], 2) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
