<?php $__env->startSection('title', 'Dashboard'); ?>

<?php $__env->startPush('styles'); ?>
<style>
    /* Hide the "Dashboard / Home" page header and tighten the top gap on this page only */
    .sms-page > .page-head { display: none !important; }
    .sms-page { padding-top: .6rem; }
</style>
<?php $__env->stopPush(); ?>

<?php
    $money = fn ($n) => 'Rs '.number_format($n);

    // Launchpad sections: [label, icon, bg-color, route, params, permission]
    $sections = [
        'Fees & Accounting' => ['bi-wallet2', [
            ['Collect Fee', 'bi-cash-stack', '#1f9d63', 'challans.index', [], 'fees.view'],
            ['Generate Challans', 'bi-receipt', '#2f8fe0', 'challans.create', [], 'fees.create'],
            ['Print Challans', 'bi-printer', '#3a5bd0', 'challans.print-form', [], 'fees.view'],
            ['Fee Records', 'bi-folder2-open', '#6d3fd4', 'challans.index', [], 'fees.view'],
            ['Defaulters', 'bi-exclamation-triangle', '#e0566a', 'fees.defaulters', [], 'fees.view'],
            ['Fee Structure', 'bi-sliders', '#16a8a8', 'fee-structure.index', [], 'fees.update'],
            ['Fee Types', 'bi-tags', '#f08a3c', 'fee-types.index', [], 'fees.update'],
            ['Concessions', 'bi-percent', '#d96e1a', 'concessions.index', [], 'fees.update'],
            ['Defaulter SMS', 'bi-chat-dots', '#e0566a', 'communication.compose', ['audience' => 'defaulters', 'channel' => 'sms'], 'communication.send'],
            ['Record Expense', 'bi-arrow-up-circle', '#495057', 'journals.expense', [], 'accounting.create'],
            ['Record Income', 'bi-arrow-down-circle', '#1f9d63', 'journals.income', [], 'accounting.create'],
            ['Balance Sheet', 'bi-bank', '#1f6ab0', 'reports.balance-sheet', [], 'accounting.view'],
            ['Trial Balance', 'bi-list-columns', '#21b6d4', 'reports.trial-balance', [], 'accounting.view'],
        ]],
        'Students & Admissions' => ['bi-mortarboard', [
            ['Students', 'bi-people', '#2f8fe0', 'students.index', [], 'students.view'],
            ['Withdrawn Students', 'bi-person-dash', '#c0453b', 'students.index', ['status' => 'withdrawn'], 'students.view'],
            ['New Admission', 'bi-person-plus', '#1f9d63', 'students.create', [], 'students.create'],
            ['Admissions', 'bi-clipboard-check', '#16a8a8', 'admissions.index', [], 'admissions.view'],
            ['Inquiries', 'bi-chat-left-dots', '#f08a3c', 'inquiries.index', [], 'inquiries.view'],
            ['Families', 'bi-house-heart', '#6d3fd4', 'families.index', [], 'families.view'],
            ['Attendance', 'bi-calendar2-check', '#2f8fe0', 'attendance.students.index', [], 'attendance.view'],
            ['Homework / LMS', 'bi-journal-arrow-up', '#d96e1a', 'materials.index', [], 'lms.view'],
            ['Certificates', 'bi-award', '#e0566a', 'certificates.index', [], 'certificates.view'],
        ]],
        'Academics & Exams' => ['bi-journal-bookmark', [
            ['Classes', 'bi-grid-3x3', '#2f8fe0', 'classes.index', [], 'academics.view'],
            ['Subjects', 'bi-book', '#16a8a8', 'subjects.index', [], 'academics.view'],
            ['Sessions', 'bi-calendar3', '#6d3fd4', 'sessions.index', [], 'academics.view'],
            ['Exams', 'bi-journal-text', '#f08a3c', 'exams.index', [], 'exams.view'],
            ['Marks Entry', 'bi-pencil-square', '#1f9d63', 'marks.index', [], 'exams.update'],
            ['Result Cards', 'bi-card-checklist', '#2f8fe0', 'results.card', [], 'exams.view'],
            ['Gazette', 'bi-table', '#d96e1a', 'results.gazette', [], 'exams.view'],
            ['Position Holders', 'bi-trophy', '#e0566a', 'results.positions', [], 'exams.view'],
        ]],
        'Operations' => ['bi-bus-front', [
            ['Transport', 'bi-bus-front', '#2f8fe0', 'transport-routes.index', [], 'transport.view'],
            ['Vehicles', 'bi-truck', '#16a8a8', 'vehicles.index', [], 'transport.view'],
            ['Visitors', 'bi-person-walking', '#f08a3c', 'visitors.index', [], 'visitors.view'],
            ['Communication', 'bi-chat-dots', '#1f9d63', 'communication.index', [], 'communication.view'],
            ['Notice Board', 'bi-megaphone', '#d96e1a', 'notices.index', [], 'notices.view'],
            ['Reports', 'bi-graph-up', '#6d3fd4', 'reports.index', [], 'reports.view'],
        ]],
        'Administration' => ['bi-gear', [
            ['Branches', 'bi-buildings', '#2f8fe0', 'branches.index', [], 'branches.view'],
            ['Users', 'bi-person-badge', '#16a8a8', 'users.index', [], 'users.view'],
            ['Roles', 'bi-shield-lock', '#6d3fd4', 'roles.index', [], 'roles.view'],
            ['Activity Log', 'bi-clock-history', '#495057', 'activity-log.index', [], 'activity_log.view'],
        ]],
    ];
?>

<?php $__env->startSection('content'); ?>
    
    <div class="row g-3 mb-3 row-cols-2 row-cols-md-3 row-cols-xl-5">
        <div class="col">
            <div class="card kpi grad-green">
                <i class="bi bi-wallet2 kpi-icon"></i>
                <div class="kpi-body"><div class="kpi-val"><?php echo e($money($stats['income_today'])); ?></div><div class="kpi-label">Income Today</div></div>
                <div class="kpi-foot"><span>This month: <?php echo e($money($stats['income_month'])); ?></span><?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('accounting.view')): ?><a href="<?php echo e(route('reports.profit-loss')); ?>"><i class="bi bi-arrow-right-circle"></i></a><?php endif; ?></div>
            </div>
        </div>
        <div class="col">
            <div class="card kpi grad-red">
                <i class="bi bi-receipt kpi-icon"></i>
                <div class="kpi-body"><div class="kpi-val"><?php echo e($money($stats['expense_today'])); ?></div><div class="kpi-label">Expense Today</div></div>
                <div class="kpi-foot"><span>This month: <?php echo e($money($stats['expense_month'])); ?></span><?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('accounting.create')): ?><a href="<?php echo e(route('journals.expense')); ?>"><i class="bi bi-arrow-right-circle"></i></a><?php endif; ?></div>
            </div>
        </div>
        <div class="col">
            <div class="card kpi grad-amber">
                <i class="bi bi-cash-coin kpi-icon"></i>
                <div class="kpi-body"><div class="kpi-val"><?php echo e($money($stats['unpaid_dues'])); ?></div><div class="kpi-label">Outstanding Dues</div></div>
                <div class="kpi-foot"><span><?php echo e(number_format($stats['unpaid_count'])); ?> unpaid invoice(s)</span><?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('fees.view')): ?><a href="<?php echo e(route('fees.defaulters')); ?>"><i class="bi bi-arrow-right-circle"></i></a><?php endif; ?></div>
            </div>
        </div>
        <div class="col">
            <div class="card kpi grad-purple">
                <i class="bi bi-cash-stack kpi-icon"></i>
                <div class="kpi-body"><div class="kpi-val"><?php echo e($money($stats['collected_today'])); ?></div><div class="kpi-label">Collected Today</div></div>
                <div class="kpi-foot"><span>This month: <?php echo e($money($stats['revenue_month'])); ?></span><?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('fees.view')): ?><a href="<?php echo e(route('reports.fee-collection')); ?>"><i class="bi bi-arrow-right-circle"></i></a><?php endif; ?></div>
            </div>
        </div>
        <div class="col">
            <div class="card kpi grad-cyan">
                <i class="bi bi-gift kpi-icon"></i>
                <div class="kpi-body"><div class="kpi-val"><?php echo e(number_format($stats['free_students'])); ?></div><div class="kpi-label">Free Students</div></div>
                <div class="kpi-foot"><span>Full-waiver concession</span><?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('students.view')): ?><a href="<?php echo e(route('students.index', ['free' => 1])); ?>"><i class="bi bi-arrow-right-circle"></i></a><?php endif; ?></div>
            </div>
        </div>
    </div>

    
    <div class="row g-3 mb-4 row-cols-2 row-cols-md-3 row-cols-xl-5">
        <?php
            $counts = [
                ['Students', $stats['students'], 'bi-mortarboard', 'grad-blue', 'students.index', 'View all', 'students.view', []],
                ['Teachers', $stats['teachers'], 'bi-person-workspace', 'grad-teal', 'users.index', 'View all', 'users.view', []],
                ['Families', $stats['parents'], 'bi-people', 'grad-orange', 'families.index', 'View all', 'families.view', []],
                ['Classes', $stats['classes'], 'bi-layers', 'grad-purple', 'classes.index', 'Manage', 'academics.view', []],
                ['Sibling Families', $stats['sibling_families'], 'bi-people-fill', 'grad-cyan', 'families.index', 'View', 'families.view', ['siblings' => 1]],
            ];
        ?>
        <?php $__currentLoopData = $counts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $value, $icon, $grad, $route, $action, $perm, $params]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="col">
                <div class="card kpi <?php echo e($grad); ?>">
                    <i class="bi <?php echo e($icon); ?> kpi-icon"></i>
                    <div class="kpi-body">
                        <div class="kpi-val"><?php echo e(number_format($value)); ?></div>
                        <div class="kpi-label"><?php echo e($label); ?></div>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check($perm)): ?><a href="<?php echo e(route($route, $params ?? [])); ?>" class="small fw-semibold text-white text-decoration-none"><?php echo e($action); ?> <i class="bi bi-arrow-right"></i></a><?php endif; ?>
                    </div>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    
    <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $title => [$secIcon, $tiles]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php $visible = collect($tiles)->filter(fn ($t) => (! $t[5] || auth()->user()->can($t[5])) && \Illuminate\Support\Facades\Route::has($t[3])); ?>
        <?php if($visible->isNotEmpty()): ?>
            <div class="card mb-3">
                <div class="card-header"><i class="bi <?php echo e($secIcon); ?> me-1"></i><?php echo e($title); ?></div>
                <div class="card-body">
                    <div class="tiles">
                        <?php $__currentLoopData = $visible; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $icon, $color, $route, $params, $perm]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <a class="tile" href="<?php echo e(route($route, $params)); ?>">
                                <span class="tile-ic" style="background:<?php echo e($color); ?>"><i class="bi <?php echo e($icon); ?>"></i></span>
                                <span class="tile-label"><?php echo e($label); ?></span>
                            </a>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

    
    <div class="row g-3">
        <div class="col-lg-7">
            <div class="card h-100">
                <div class="card-header"><i class="bi bi-graph-up me-1"></i>Revenue Trend (6 Months)</div>
                <div class="card-body"><canvas id="revenueChart" height="120"></canvas></div>
            </div>
        </div>
        <div class="col-lg-5">
            <div class="card h-100">
                <div class="card-header"><i class="bi bi-pie-chart me-1"></i>Active Students by Class</div>
                <div class="card-body"><canvas id="classChart" height="120"></canvas></div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
    const primary = 'rgba(79,70,229,.85)';
    const palette = ['#4f46e5','#0aa2c0','#198754','#ffc107','#dc3545','#7c3aed','#fd7e14','#20c997'];

    new Chart(document.getElementById('revenueChart'), {
        type: 'line',
        data: {
            labels: <?php echo json_encode($revenueTrend->pluck('label'), 15, 512) ?>,
            datasets: [{ label: 'Revenue', data: <?php echo json_encode($revenueTrend->pluck('value'), 15, 512) ?>, borderColor: primary, backgroundColor: 'rgba(79,70,229,.12)', fill: true, tension: .35, pointRadius: 3 }]
        },
        options: { plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true } } }
    });

    const classData = <?php echo json_encode($studentsByClass, 15, 512) ?>;
    new Chart(document.getElementById('classChart'), {
        type: 'doughnut',
        data: { labels: classData.map(d => d.label), datasets: [{ data: classData.map(d => d.value), backgroundColor: palette }] },
        options: { plugins: { legend: { position: 'right', labels: { boxWidth: 12, font: { size: 10 } } } } }
    });
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/u385418287/domains/itartificer.com/public_html/sms-erp/resources/views/dashboard.blade.php ENDPATH**/ ?>