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

<?php $__template->section('title'); ?>ميزانية موحدة<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:15px;">
    <div style="padding:15px 20px;">
        <form method="GET" action="/accounting/reports/consolidated-balance-sheet" style="display:flex;gap:10px;align-items:end;">
            <div>
                <label class="form-label" style="font-size:12px;">حتى تاريخ</label>
                <input type="date" name="as_of_date" class="form-input" value="<?= e($as_of_date) ?>">
            </div>
            <button type="submit" class="btn btn-primary">عرض</button>
        </form>
    </div>
</div>

<!-- Consolidated -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;text-align:center;background:#0D7377;color:white;">
        <h2 style="margin:0;">الميزانية الموحدة</h2>
        <p style="margin:5px 0 0;opacity:0.8;">حتى تاريخ <?= e($as_of_date) ?></p>
    </div>
    <div style="padding:20px;display:grid;grid-template-columns:repeat(3,1fr);gap:20px;text-align:center;">
        <div>
            <div style="font-size:14px;color:#6B7280;">إجمالي الأصول</div>
            <div style="font-size:24px;font-weight:700;color:#0D7377;"><?= money($result['consolidated']['total_assets']) ?></div>
        </div>
        <div>
            <div style="font-size:14px;color:#6B7280;">إجمالي الخصوم</div>
            <div style="font-size:24px;font-weight:700;color:#DC2626;"><?= money($result['consolidated']['total_liabilities']) ?></div>
        </div>
        <div>
            <div style="font-size:14px;color:#6B7280;">حقوق الملكية</div>
            <div style="font-size:24px;font-weight:700;color:#7C3AED;"><?= money($result['consolidated']['total_equity']) ?></div>
        </div>
    </div>
</div>

<!-- Per Branch -->
<?php foreach ($result['branch_sheets'] as $bs): ?>
    <div class="card" style="margin-bottom:15px;">
        <div style="padding:12px 20px;border-bottom:1px solid #E5E7EB;">
            <h3 style="margin:0;"><?= e($bs['branch']['name_ar']) ?></h3>
        </div>
        <div style="padding:15px 20px;display:grid;grid-template-columns:repeat(3,1fr);gap:15px;text-align:center;">
            <div>
                <div style="font-size:12px;color:#6B7280;">الأصول</div>
                <div style="font-size:18px;font-weight:600;"><?= money($bs['balance_sheet']['total_assets']) ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;">الخصوم</div>
                <div style="font-size:18px;font-weight:600;"><?= money($bs['balance_sheet']['total_liabilities']) ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;">حقوق الملكية</div>
                <div style="font-size:18px;font-weight:600;"><?= money($bs['balance_sheet']['total_equity']) ?></div>
            </div>
        </div>
    </div>
<?php endforeach; ?>
<?php $__template->endSection(); ?>
