<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تقرير الإهلاك<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<button onclick="window.print()" class="btn btn-outline"><i data-lucide="printer" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> طباعة</button>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<!-- Filter -->
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/inventory/reports/depreciation" style="display:flex;gap:10px;align-items:end;">
        <div style="min-width:200px;">
            <label class="form-label" style="font-size:12px;">الشهر</label>
            <input type="month" name="month" value="<?= e($month ?? '') ?>" class="form-input">
        </div>
        <button type="submit" class="btn btn-primary"><i data-lucide="search" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> عرض التقرير</button>
    </form>
</div>

<?php if (!empty($entries)): ?>

<!-- Total Depreciation Card -->
<div class="card" style="margin-bottom:20px;padding:20px;text-align:center;background:#EFF6FF;border:1px solid #BFDBFE;">
    <div style="font-size:14px;color:#6B7280;margin-bottom:6px;">إجمالي إهلاك الفترة</div>
    <div style="font-size:32px;font-weight:700;color:#2563EB;"><?= money($totalDep ?? 0) ?></div>
    <?php if (!empty($month)): ?>
    <div style="font-size:13px;color:#9CA3AF;margin-top:4px;"><?= e($month) ?></div>
    <?php endif; ?>
</div>

<!-- Depreciation Table -->
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
        <i data-lucide="trending-down" style="width:20px;height:20px;color:#2563EB;"></i>
        <h3 style="margin:0;color:#0D7377;">تفاصيل الإهلاك</h3>
    </div>
    <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 ($entries as $entry): ?>
                <tr>
                    <td style="font-family:monospace;font-weight:600;"><?= e($entry['asset_tag'] ?? '—') ?></td>
                    <td style="font-weight:600;"><?= e($entry['item_name']) ?></td>
                    <td><?= e($entry['warehouse_name'] ?? '—') ?></td>
                    <td style="font-weight:600;direction:ltr;text-align:right;"><?= money($entry['purchase_cost'] ?? 0) ?></td>
                    <td style="font-weight:700;color:#2563EB;direction:ltr;text-align:right;"><?= money($entry['depreciation_amount'] ?? 0) ?></td>
                    <td style="font-weight:600;color:#D97706;direction:ltr;text-align:right;"><?= money($entry['accumulated_total'] ?? 0) ?></td>
                    <td style="font-weight:700;color:#059669;direction:ltr;text-align:right;"><?= money($entry['book_value_after'] ?? 0) ?></td>
                    <td>
                        <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#F3F4F6;color:#6B7280;">
                            <?= e($entry['method_used'] ?? '—') ?>
                        </span>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
            <tfoot>
                <tr style="background:#EFF6FF;font-weight:700;">
                    <td colspan="4" style="padding:12px 15px;">الإجمالي</td>
                    <td style="padding:12px 15px;direction:ltr;text-align:right;font-size:16px;color:#2563EB;"><?= money($totalDep ?? 0) ?></td>
                    <td colspan="3"></td>
                </tr>
            </tfoot>
        </table>
    </div>
</div>

<?php else: ?>
<div class="card" style="padding:60px 20px;text-align:center;">
    <div style="margin-bottom:15px;">
        <i data-lucide="calendar" style="width:48px;height:48px;color:#D1D5DB;"></i>
    </div>
    <h3 style="color:#6B7280;margin:0 0 8px;">لا توجد بيانات إهلاك</h3>
    <p style="color:#9CA3AF;font-size:14px;margin:0;">اختر الشهر لعرض تقرير الإهلاك</p>
</div>
<?php endif; ?>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') {
        lucide.createIcons();
    }
});
</script>
<?php $__template->endSection(); ?>
