<?php $__env->startSection('page_title', 'Admin Dashboard - ' . $branding['company_name']); ?>

<?php $__env->startSection('content'); ?>


<div class="dashboard-welcome mb-3 mb-md-4">
    <div class="d-flex flex-wrap justify-content-between align-items-start gap-2 gap-md-3">
        <div class="min-w-0">
            <p class="text-muted small mb-1 fw-semibold text-uppercase d-none d-sm-block"><?php echo e(now()->format('l, F j, Y')); ?></p>
            <p class="text-muted mb-1 fw-semibold text-uppercase d-sm-none" style="font-size:0.65rem;"><?php echo e(now()->format('M j, Y')); ?></p>
            <h4 class="fw-bold text-secondary mb-1 dashboard-welcome-title">Welcome, <?php echo e(Auth::user()->name); ?></h4>
            <p class="text-muted mb-0 small d-none d-md-block">Here's what's happening at <?php echo e($branding['company_name']); ?> today.</p>
        </div>
        <div class="d-flex flex-wrap gap-1 gap-md-2 w-100 w-sm-auto">
            <a href="<?php echo e(route('admin.products.create')); ?>" class="btn btn-danger btn-sm rounded-pill px-2 px-md-3 flex-grow-1 flex-sm-grow-0">
                <i class="bi bi-plus-lg me-1"></i> Add Product
            </a>
            <a href="<?php echo e(route('admin.orders.index')); ?>" class="btn btn-outline-secondary btn-sm rounded-pill px-2 px-md-3">
                <i class="bi bi-cart3 me-1"></i> Orders
            </a>
            <a href="<?php echo e(route('admin.slides.index')); ?>" class="btn btn-outline-secondary btn-sm rounded-pill px-2 px-md-3 d-none d-sm-inline-flex">
                <i class="bi bi-images me-1"></i> Hero Slides
            </a>
        </div>
    </div>
</div>


<?php if($pendingActions > 0): ?>
<div class="alert alert-warning border-0 rounded-4 shadow-sm d-flex align-items-center gap-3 mb-4" role="alert">
    <div class="rounded-circle bg-warning bg-opacity-25 text-warning d-flex align-items-center justify-content-center flex-shrink-0" style="width:42px;height:42px;">
        <i class="bi bi-bell-fill"></i>
    </div>
    <div class="flex-grow-1">
        <strong><?php echo e($pendingActions); ?> item<?php echo e($pendingActions > 1 ? 's' : ''); ?> need your attention</strong>
        <div class="small mt-1">
            <?php if($pendingOrders > 0): ?><span class="me-3"><i class="bi bi-cart3 me-1"></i><?php echo e($pendingOrders); ?> pending order<?php echo e($pendingOrders > 1 ? 's' : ''); ?></span><?php endif; ?>
            <?php if($pendingBookings > 0): ?><span class="me-3"><i class="bi bi-tools me-1"></i><?php echo e($pendingBookings); ?> repair booking<?php echo e($pendingBookings > 1 ? 's' : ''); ?></span><?php endif; ?>
            <?php if($pendingQuotations > 0): ?><span class="me-3"><i class="bi bi-chat-quote me-1"></i><?php echo e($pendingQuotations); ?> quotation<?php echo e($pendingQuotations > 1 ? 's' : ''); ?></span><?php endif; ?>
            <?php if($unreadMessages > 0): ?><span><i class="bi bi-envelope me-1"></i><?php echo e($unreadMessages); ?> unread message<?php echo e($unreadMessages > 1 ? 's' : ''); ?></span><?php endif; ?>
        </div>
    </div>
</div>
<?php endif; ?>


<div class="row g-2 g-md-3 mb-2 mb-md-3">
    <div class="col-6 col-sm-6 col-xl-3">
        <div class="card dashboard-stat-card p-2 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-start gap-1">
                <div class="dashboard-stat-body min-w-0">
                    <span class="dashboard-stat-label">Total Revenue</span>
                    <h3 class="dashboard-stat-value">KSh <?php echo e(number_format($totalRevenue)); ?></h3>
                    <span class="dashboard-stat-sub <?php echo e($revenueChange >= 0 ? 'text-success' : 'text-danger'); ?>">
                        <i class="bi bi-<?php echo e($revenueChange >= 0 ? 'arrow-up-short' : 'arrow-down-short'); ?>"></i>
                        <?php echo e(abs($revenueChange)); ?>%<span class="d-none d-md-inline"> vs last month</span>
                    </span>
                </div>
                <div class="dashboard-stat-icon bg-success-subtle text-success flex-shrink-0"><i class="bi bi-wallet2"></i></div>
            </div>
        </div>
    </div>
    <div class="col-6 col-sm-6 col-xl-3">
        <div class="card dashboard-stat-card p-2 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-start gap-1">
                <div class="dashboard-stat-body min-w-0">
                    <span class="dashboard-stat-label">This Month</span>
                    <h3 class="dashboard-stat-value">KSh <?php echo e(number_format($thisMonthRevenue)); ?></h3>
                    <span class="dashboard-stat-sub text-muted"><?php echo e($thisMonthOrders); ?> order<?php echo e($thisMonthOrders !== 1 ? 's' : ''); ?></span>
                </div>
                <div class="dashboard-stat-icon bg-danger-subtle text-danger flex-shrink-0"><i class="bi bi-graph-up-arrow"></i></div>
            </div>
        </div>
    </div>
    <div class="col-6 col-sm-6 col-xl-3">
        <div class="card dashboard-stat-card p-2 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-start gap-1">
                <div class="dashboard-stat-body min-w-0">
                    <span class="dashboard-stat-label">Total Orders</span>
                    <h3 class="dashboard-stat-value"><?php echo e(number_format($totalOrders)); ?></h3>
                    <span class="dashboard-stat-sub text-warning">
                        <span class="d-inline d-xl-none"><?php echo e($pendingOrders); ?>p · <?php echo e($processingOrders); ?> active</span>
                        <span class="d-none d-xl-inline"><?php echo e($pendingOrders); ?> pending · <?php echo e($processingOrders); ?> in progress</span>
                    </span>
                </div>
                <div class="dashboard-stat-icon bg-warning-subtle text-warning flex-shrink-0"><i class="bi bi-cart3"></i></div>
            </div>
        </div>
    </div>
    <div class="col-6 col-sm-6 col-xl-3">
        <div class="card dashboard-stat-card p-2 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-start gap-1">
                <div class="dashboard-stat-body min-w-0">
                    <span class="dashboard-stat-label">Customers</span>
                    <h3 class="dashboard-stat-value"><?php echo e(number_format($totalCustomers)); ?></h3>
                    <span class="dashboard-stat-sub text-muted d-none d-sm-inline">Registered accounts</span>
                    <span class="dashboard-stat-sub text-muted d-sm-none">Accounts</span>
                </div>
                <div class="dashboard-stat-icon bg-primary-subtle text-primary flex-shrink-0"><i class="bi bi-people"></i></div>
            </div>
        </div>
    </div>
</div>


<div class="row g-2 g-md-3 mb-3 mb-md-4">
    <div class="col-6 col-md-4 col-xl-2">
        <div class="card dashboard-mini-stat p-2 p-md-3 text-center h-100">
            <div class="dashboard-mini-stat-icon text-danger mx-auto mb-1 mb-md-2"><i class="bi bi-bicycle"></i></div>
            <div class="dashboard-mini-stat-value fw-bold text-secondary"><?php echo e($totalProducts); ?></div>
            <div class="small text-muted" style="font-size:0.7rem;">Products</div>
            <div class="small text-muted d-none d-md-block"><?php echo e($totalBikes); ?> bikes</div>
        </div>
    </div>
    <div class="col-6 col-md-4 col-xl-2">
        <div class="card dashboard-mini-stat p-2 p-md-3 text-center h-100">
            <div class="dashboard-mini-stat-icon text-info mx-auto mb-1 mb-md-2"><i class="bi bi-tools"></i></div>
            <div class="dashboard-mini-stat-value fw-bold text-secondary"><?php echo e($pendingBookings); ?></div>
            <div class="small text-muted" style="font-size:0.7rem;">Repairs</div>
        </div>
    </div>
    <div class="col-6 col-md-4 col-xl-2">
        <div class="card dashboard-mini-stat p-2 p-md-3 text-center h-100">
            <div class="dashboard-mini-stat-icon text-warning mx-auto mb-1 mb-md-2"><i class="bi bi-chat-quote"></i></div>
            <div class="dashboard-mini-stat-value fw-bold text-secondary"><?php echo e($pendingQuotations); ?></div>
            <div class="small text-muted" style="font-size:0.7rem;">Quotes</div>
        </div>
    </div>
    <div class="col-6 col-md-4 col-xl-2">
        <div class="card dashboard-mini-stat p-2 p-md-3 text-center h-100">
            <div class="dashboard-mini-stat-icon text-success mx-auto mb-1 mb-md-2"><i class="bi bi-images"></i></div>
            <div class="dashboard-mini-stat-value fw-bold text-secondary"><?php echo e($activeSlides); ?></div>
            <div class="small text-muted" style="font-size:0.7rem;">Slides</div>
        </div>
    </div>
    <div class="col-6 col-md-4 col-xl-2">
        <div class="card dashboard-mini-stat p-2 p-md-3 text-center h-100">
            <div class="dashboard-mini-stat-icon text-primary mx-auto mb-1 mb-md-2"><i class="bi bi-journal-text"></i></div>
            <div class="dashboard-mini-stat-value fw-bold text-secondary"><?php echo e($publishedPosts); ?></div>
            <div class="small text-muted" style="font-size:0.7rem;">Blog</div>
        </div>
    </div>
    <div class="col-6 col-md-4 col-xl-2">
        <div class="card dashboard-mini-stat p-2 p-md-3 text-center h-100 <?php echo e($lowStockCount > 0 ? 'border-warning' : ''); ?>">
            <div class="dashboard-mini-stat-icon text-danger mx-auto mb-1 mb-md-2"><i class="bi bi-exclamation-triangle"></i></div>
            <div class="dashboard-mini-stat-value fw-bold text-secondary"><?php echo e($lowStockCount); ?></div>
            <div class="small text-muted" style="font-size:0.7rem;">Low Stock</div>
        </div>
    </div>
</div>


<div class="row g-2 g-md-4 mb-3 mb-md-4">
    <div class="col-lg-8">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <div>
                    <h6 class="fw-bold text-secondary mb-0">Revenue Overview</h6>
                    <span class="small text-muted">Paid orders — <?php echo e($year); ?></span>
                </div>
                <span class="badge bg-danger-subtle text-danger rounded-pill">KSh</span>
            </div>
            <div class="dashboard-chart-wrap" style="height:280px;position:relative;">
                <canvas id="revenueChart"></canvas>
                <?php if (! ($hasRevenueData)): ?>
                <div class="dashboard-chart-empty">
                    <i class="bi bi-bar-chart-line fs-2 text-muted mb-2 d-block"></i>
                    <p class="small text-muted mb-0">No paid orders yet this year.<br>Revenue will appear here once payments are recorded.</p>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <div>
                    <h6 class="fw-bold text-secondary mb-0">Order Volume</h6>
                    <span class="small text-muted">All orders — <?php echo e($year); ?></span>
                </div>
            </div>
            <div class="dashboard-chart-wrap" style="height:280px;position:relative;">
                <canvas id="ordersChart"></canvas>
                <?php if (! ($hasOrderData)): ?>
                <div class="dashboard-chart-empty">
                    <i class="bi bi-cart-x fs-2 text-muted mb-2 d-block"></i>
                    <p class="small text-muted mb-0">No orders placed yet this year.</p>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>


<div class="row g-2 g-md-4 mb-3 mb-md-4">
    <div class="col-md-4">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <h6 class="fw-bold text-secondary mb-3">Order Status</h6>
            <?php if(count($orderStatusBreakdown) > 0): ?>
                <div style="height:200px;position:relative;">
                    <canvas id="orderStatusChart"></canvas>
                </div>
                <ul class="list-unstyled mt-3 mb-0">
                    <?php $__currentLoopData = $orderStatusBreakdown; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status => $count): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="d-flex justify-content-between small py-1 border-bottom border-light">
                        <span class="text-capitalize text-muted"><?php echo e(str_replace('_', ' ', $status)); ?></span>
                        <span class="fw-bold text-secondary"><?php echo e($count); ?></span>
                    </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            <?php else: ?>
                <div class="text-center py-5 text-muted">
                    <i class="bi bi-pie-chart fs-2 d-block mb-2 opacity-50"></i>
                    <p class="small mb-0">No orders to display</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <h6 class="fw-bold text-secondary mb-3">Repair Bookings</h6>
            <?php if(count($bookingStatusBreakdown) > 0): ?>
                <ul class="list-unstyled mb-0">
                    <?php $__currentLoopData = $bookingStatusBreakdown; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status => $count): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="d-flex align-items-center justify-content-between py-2 border-bottom border-light">
                        <span class="text-capitalize small text-muted"><?php echo e($status); ?></span>
                        <span class="badge bg-<?php echo e($status === 'completed' ? 'success' : ($status === 'confirmed' ? 'info' : 'warning')); ?> bg-opacity-10 text-<?php echo e($status === 'completed' ? 'success' : ($status === 'confirmed' ? 'info' : 'warning')); ?> rounded-pill"><?php echo e($count); ?></span>
                    </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
                <a href="<?php echo e(route('admin.bookings.index')); ?>" class="btn btn-sm btn-outline-secondary rounded-pill w-100 mt-3">Manage Bookings</a>
            <?php else: ?>
                <div class="text-center py-5 text-muted">
                    <i class="bi bi-tools fs-2 d-block mb-2 opacity-50"></i>
                    <p class="small mb-0">No repair bookings yet</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h6 class="fw-bold text-secondary mb-0">Low Stock Alert</h6>
                <?php if($lowStockCount > 0): ?>
                <span class="badge bg-warning text-dark rounded-pill"><?php echo e($lowStockCount); ?></span>
                <?php endif; ?>
            </div>
            <?php if($lowStockProducts->count() > 0): ?>
                <ul class="list-unstyled mb-0">
                    <?php $__currentLoopData = $lowStockProducts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="d-flex align-items-center justify-content-between py-2 border-bottom border-light">
                        <div class="small text-truncate me-2" style="max-width:70%;">
                            <a href="<?php echo e(route('admin.products.edit', $product->id)); ?>" class="text-decoration-none text-secondary fw-semibold"><?php echo e($product->name); ?></a>
                        </div>
                        <span class="badge bg-danger bg-opacity-10 text-danger rounded-pill"><?php echo e($product->stock_quantity); ?> left</span>
                    </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
                <a href="<?php echo e(route('admin.products.index')); ?>" class="btn btn-sm btn-outline-danger rounded-pill w-100 mt-3">View All Products</a>
            <?php else: ?>
                <div class="text-center py-5 text-muted">
                    <i class="bi bi-check-circle fs-2 d-block mb-2 text-success opacity-75"></i>
                    <p class="small mb-0">All products are well stocked</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>


<div class="row g-2 g-md-4">
    <div class="col-lg-6">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-center mb-3 border-bottom pb-2">
                <h6 class="fw-bold text-secondary mb-0"><i class="bi bi-cart3 me-2 text-danger"></i>Recent Orders</h6>
                <a href="<?php echo e(route('admin.orders.index')); ?>" class="text-danger text-decoration-none small fw-semibold">View All</a>
            </div>
            <?php if($recentOrders->count() > 0): ?>
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0 dashboard-table">
                    <thead>
                        <tr>
                            <th>Order</th>
                            <th>Customer</th>
                            <th>Amount</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $recentOrders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ord): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><a href="<?php echo e(route('admin.orders.show', $ord->id)); ?>" class="fw-bold text-decoration-none text-secondary">#<?php echo e($ord->order_number); ?></a></td>
                            <td class="text-muted small text-truncate" style="max-width:100px;"><?php echo e($ord->user->name ?? $ord->phone); ?></td>
                            <td class="fw-semibold small">KSh <?php echo e(number_format($ord->total_amount)); ?></td>
                            <td><span class="badge status-badge status-<?php echo e($ord->status); ?>"><?php echo e(ucfirst($ord->status)); ?></span></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
            <?php else: ?>
            <div class="dashboard-empty-state">
                <i class="bi bi-cart3"></i>
                <p>No orders yet</p>
                <span class="small">Orders from customers will appear here.</span>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <div class="col-lg-6">
        <div class="card dashboard-panel p-3 p-md-4 h-100">
            <div class="d-flex justify-content-between align-items-center mb-3 border-bottom pb-2">
                <h6 class="fw-bold text-secondary mb-0"><i class="bi bi-tools me-2 text-info"></i>Recent Repair Bookings</h6>
                <a href="<?php echo e(route('admin.bookings.index')); ?>" class="text-danger text-decoration-none small fw-semibold">View All</a>
            </div>
            <?php if($recentBookings->count() > 0): ?>
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0 dashboard-table">
                    <thead>
                        <tr>
                            <th>Customer</th>
                            <th>Bike</th>
                            <th>Date</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $recentBookings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><a href="<?php echo e(route('admin.bookings.show', $bk->id)); ?>" class="fw-bold text-decoration-none text-secondary"><?php echo e($bk->name); ?></a></td>
                            <td class="text-muted small"><?php echo e($bk->bike_type); ?></td>
                            <td class="text-muted small"><?php echo e($bk->preferred_date->format('d M Y')); ?></td>
                            <td><span class="badge status-badge status-<?php echo e($bk->status); ?>"><?php echo e(ucfirst($bk->status)); ?></span></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
            <?php else: ?>
            <div class="dashboard-empty-state">
                <i class="bi bi-tools"></i>
                <p>No repair bookings yet</p>
                <span class="small">Service requests will appear here.</span>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <div class="col-12">
        <div class="card dashboard-panel p-3 p-md-4">
            <div class="d-flex justify-content-between align-items-center mb-3 border-bottom pb-2">
                <h6 class="fw-bold text-secondary mb-0"><i class="bi bi-chat-quote me-2 text-warning"></i>Recent Quotation Requests</h6>
                <a href="<?php echo e(route('admin.quotations.index')); ?>" class="text-danger text-decoration-none small fw-semibold">View All</a>
            </div>
            <?php if($recentQuotations->count() > 0): ?>
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0 dashboard-table">
                    <thead>
                        <tr>
                            <th>Customer</th>
                            <th>Product</th>
                            <th>Phone</th>
                            <th>Date</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $recentQuotations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $quote): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td class="fw-semibold small"><?php echo e($quote->name); ?></td>
                            <td class="text-muted small"><?php echo e($quote->product->name ?? '—'); ?></td>
                            <td class="text-muted small"><?php echo e($quote->phone); ?></td>
                            <td class="text-muted small"><?php echo e($quote->created_at->format('d M Y')); ?></td>
                            <td><span class="badge status-badge status-<?php echo e($quote->status); ?>"><?php echo e(ucfirst($quote->status)); ?></span></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
            <?php else: ?>
            <div class="dashboard-empty-state py-4">
                <i class="bi bi-chat-quote"></i>
                <p>No quotation requests yet</p>
                <span class="small">Price quote requests from the marketplace will appear here.</span>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script data-turbo-eval="true">
function initDashboardCharts() {
    if (!document.getElementById('revenueChart')) return;

    ['revenueChart', 'ordersChart', 'orderStatusChart'].forEach(function (id) {
        const el = document.getElementById(id);
        if (el && Chart.getChart(el)) Chart.getChart(el).destroy();
    });

    const months = <?php echo json_encode($months, 15, 512) ?>;
    const revenueData = <?php echo json_encode($revenueTotals, 15, 512) ?>;
    const orderData = <?php echo json_encode($orderTotals, 15, 512) ?>;
    const orderStatus = <?php echo json_encode(array_values($orderStatusBreakdown), 15, 512) ?>;
    const orderStatusLabels = <?php echo json_encode($orderStatusLabels, 15, 512) ?>;

    const chartDefaults = {
        responsive: true,
        maintainAspectRatio: false,
        plugins: { legend: { display: false } },
    };

    const revenueMax = Math.max(...revenueData, 0);
    new Chart(document.getElementById('revenueChart'), {
        type: 'line',
        data: {
            labels: months,
            datasets: [{
                label: 'Revenue (KSh)',
                data: revenueData,
                borderColor: '#f97316',
                backgroundColor: 'rgba(249, 115, 22, 0.08)',
                borderWidth: 2.5,
                fill: true,
                tension: 0.4,
                pointBackgroundColor: '#f97316',
                pointBorderColor: '#fff',
                pointBorderWidth: 2,
                pointRadius: revenueData.some(v => v > 0) ? 4 : 0,
            }]
        },
        options: {
            ...chartDefaults,
            scales: {
                x: { grid: { display: false }, ticks: { font: { size: 11 } } },
                y: {
                    beginAtZero: true,
                    suggestedMax: revenueMax > 0 ? undefined : 10000,
                    grid: { color: 'rgba(0,0,0,0.05)' },
                    ticks: {
                        font: { size: 11 },
                        callback: v => 'KSh ' + Number(v).toLocaleString(),
                    }
                }
            }
        }
    });

    const orderMax = Math.max(...orderData, 0);
    new Chart(document.getElementById('ordersChart'), {
        type: 'bar',
        data: {
            labels: months,
            datasets: [{
                label: 'Orders',
                data: orderData,
                backgroundColor: 'rgba(17, 17, 22, 0.75)',
                borderRadius: 6,
                barThickness: 14,
            }]
        },
        options: {
            ...chartDefaults,
            scales: {
                x: { grid: { display: false }, ticks: { font: { size: 10 } } },
                y: {
                    beginAtZero: true,
                    suggestedMax: orderMax > 0 ? undefined : 5,
                    ticks: { stepSize: 1, font: { size: 11 } },
                    grid: { color: 'rgba(0,0,0,0.05)' },
                }
            }
        }
    });

    <?php if(count($orderStatusBreakdown) > 0): ?>
    new Chart(document.getElementById('orderStatusChart'), {
        type: 'doughnut',
        data: {
            labels: orderStatusLabels,
            datasets: [{
                data: orderStatus,
                backgroundColor: ['#f97316', '#3b82f6', '#22c55e', '#eab308', '#ef4444', '#8b5cf6'],
                borderWidth: 0,
                hoverOffset: 6,
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            cutout: '65%',
            plugins: { legend: { display: false } },
        }
    });
    <?php endif; ?>
}

document.addEventListener('DOMContentLoaded', initDashboardCharts);
document.addEventListener('turbo:page-ready', initDashboardCharts);
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\mjs-bikes-marketplace\resources\views/admin/dashboard.blade.php ENDPATH**/ ?>