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

<?php $__env->startSection('content'); ?>
<style>
.dashboard-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 1.5rem 2rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}
.stat-card {
    border: none;
    border-radius: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
.stat-card .card-body {
    padding: 1.25rem;
}
.quick-action-btn {
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    transition: all 0.2s;
    border: 1px solid #e0e0e0;
    background: white;
}
.quick-action-btn:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: translateY(-2px);
}
.quick-action-btn i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: #667eea;
}
.recent-order-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid #f0f0f0;
}
.recent-order-item:last-child {
    border-bottom: none;
}
.top-product-item {
    padding: 0.5rem 0;
}
.top-product-item .rank {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.8rem;
}
.alert-card {
    border-left: 4px solid;
    border-radius: 8px;
}
.alert-card.warning { border-left-color: #ffc107; }
.alert-card.danger { border-left-color: #dc3545; }
.alert-card.info { border-left-color: #0dcaf0; }
.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.section-title i {
    color: #667eea;
}
</style>

<div class="dashboard-header">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h2 class="mb-1">Welcome back, <?php echo e(Auth::user()->name); ?></h2>
            <p class="mb-0 opacity-75">
                <i class="bi bi-calendar3 me-1"></i>
                <?php echo e(\Carbon\Carbon::now()->format('l, F j, Y')); ?>

            </p>
        </div>
        <div class="text-end">
            <a href="<?php echo e(route('pos.sales')); ?>" class="btn btn-light btn-lg">
                <i class="bi bi-plus-circle me-2"></i>New Sale
            </a>
        </div>
    </div>
</div>

<?php if($lowStockProducts > 0): ?>
<div class="alert alert-warning d-flex align-items-center alert-dismissible fade show mb-4" role="alert">
    <i class="bi bi-exclamation-triangle-fill me-2 fs-4"></i>
    <div class="flex-grow-1">
        <strong><?php echo e($lowStockProducts); ?> product(s)</strong> are running low on stock
    </div>
    <a href="<?php echo e(route('products.index', ['low_stock' => 1])); ?>" class="btn btn-sm btn-warning">View</a>
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>

<?php if(($creditSummary['overdue_count'] ?? 0) > 0): ?>
<div class="alert alert-danger d-flex align-items-center alert-dismissible fade show mb-4" role="alert">
    <i class="bi bi-exclamation-octagon-fill me-2 fs-4"></i>
    <div class="flex-grow-1">
        <strong><?php echo e($creditSummary['overdue_count']); ?> overdue credit order(s)</strong> require attention
    </div>
    <a href="<?php echo e(route('credit.index', ['overdue' => 1])); ?>" class="btn btn-sm btn-danger">View</a>
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>

<div class="row g-4 mb-4">
    <div class="col-lg-3 col-md-6">
        <div class="card stat-card h-100">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="flex-grow-1">
                        <p class="text-muted mb-1 small text-uppercase fw-semibold">Today's Sales</p>
                        <h3 class="mb-0 text-primary">Kes <?php echo e(number_format($dailySales, 0)); ?></h3>
                        <small class="text-success">
                            <i class="bi bi-arrow-up"></i> <?php echo e($todayOrders); ?> orders
                        </small>
                    </div>
                    <div class="ms-3">
                        <div class="rounded-circle p-3" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
                            <i class="bi bi-currency-dollar text-white fs-4"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-6">
        <div class="card stat-card h-100">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="flex-grow-1">
                        <p class="text-muted mb-1 small text-uppercase fw-semibold">This Week</p>
                        <h3 class="mb-0 text-success">Kes <?php echo e(number_format($weeklySales, 0)); ?></h3>
                        <small class="text-muted">
                            <i class="bi bi-calendar-week"></i> Last 7 days
                        </small>
                    </div>
                    <div class="ms-3">
                        <div class="rounded-circle p-3" style="background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);">
                            <i class="bi bi-graph-up-arrow text-white fs-4"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-6">
        <div class="card stat-card h-100">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="flex-grow-1">
                        <p class="text-muted mb-1 small text-uppercase fw-semibold">This Month</p>
                        <h3 class="mb-0" style="color: #f5576c;">Kes <?php echo e(number_format($monthlySales, 0)); ?></h3>
                        <small class="text-muted">
                            <i class="bi bi-calendar-month"></i> <?php echo e(\Carbon\Carbon::now()->format('F Y')); ?>

                        </small>
                    </div>
                    <div class="ms-3">
                        <div class="rounded-circle p-3" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
                            <i class="bi bi-calendar3 text-white fs-4"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-6">
        <div class="card stat-card h-100">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="flex-grow-1">
                        <p class="text-muted mb-1 small text-uppercase fw-semibold">Credit Outstanding</p>
                        <h3 class="mb-0 text-danger">Kes <?php echo e(number_format($creditSummary['outstanding'] ?? 0, 0)); ?></h3>
                        <small class="text-muted">
                            <i class="bi bi-credit-card"></i> <?php echo e($creditSummary['overdue_count'] ?? 0); ?> overdue
                        </small>
                    </div>
                    <div class="ms-3">
                        <div class="rounded-circle p-3" style="background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);">
                            <i class="bi bi-credit-card-fill text-white fs-4"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row g-4 mb-4">
    <div class="col-lg-3 col-md-6">
        <div class="card stat-card h-100">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="flex-grow-1">
                        <p class="text-muted mb-1 small text-uppercase fw-semibold">Credit Recovered (Month)</p>
                        <h3 class="mb-0 text-success">Kes <?php echo e(number_format($creditSummary['recovered_month'] ?? 0, 0)); ?></h3>
                        <small class="text-muted">
                            <i class="bi bi-check-circle"></i> <?php echo e(number_format($creditSummary['recovered_today'] ?? 0, 0)); ?> today
                        </small>
                    </div>
                    <div class="ms-3">
                        <div class="rounded-circle p-3" style="background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);">
                            <i class="bi bi-cash-coin text-white fs-4"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-6">
        <div class="card stat-card h-100">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="flex-grow-1">
                        <p class="text-muted mb-1 small text-uppercase fw-semibold">Low Stock Items</p>
                        <h3 class="mb-0 <?php echo e($lowStockProducts > 0 ? 'text-warning' : 'text-success'); ?>">
                            <?php echo e($lowStockProducts); ?>

                        </h3>
                        <small class="text-muted">
                            <i class="bi bi-box-seam"></i> Need restocking
                        </small>
                    </div>
                    <div class="ms-3">
                        <div class="rounded-circle p-3 <?php echo e($lowStockProducts > 0 ? 'bg-warning' : ''); ?>" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
                            <i class="bi bi-box-seam text-white fs-4"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row g-4">
    <div class="col-md-4">
        <div class="card h-100">
            <div class="card-header bg-transparent border-0 pt-3">
                <h5 class="section-title mb-0"><i class="bi bi-lightning-fill"></i> Quick Actions</h5>
            </div>
            <div class="card-body pt-0">
                <div class="row g-2">
                    <div class="col-6">
                        <a href="<?php echo e(route('pos.sales')); ?>" class="quick-action-btn d-block text-decoration-none">
                            <i class="bi bi-cart-plus-fill d-block"></i>
                            <small class="text-dark">New Sale</small>
                        </a>
                    </div>
                    <div class="col-6">
                        <a href="<?php echo e(route('orders.index')); ?>" class="quick-action-btn d-block text-decoration-none">
                            <i class="bi bi-receipt d-block"></i>
                            <small class="text-dark">Orders</small>
                        </a>
                    </div>
                    <div class="col-6">
                        <a href="<?php echo e(route('inventory.stock-in')); ?>" class="quick-action-btn d-block text-decoration-none">
                            <i class="bi bi-plus-circle d-block"></i>
                            <small class="text-dark">Stock In</small>
                        </a>
                    </div>
                    <div class="col-6">
                        <a href="<?php echo e(route('reports.sales')); ?>" class="quick-action-btn d-block text-decoration-none">
                            <i class="bi bi-graph-up d-block"></i>
                            <small class="text-dark">Reports</small>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-8">
        <div class="card h-100">
            <div class="card-header bg-transparent border-0 pt-3 d-flex justify-content-between align-items-center">
                <h5 class="section-title mb-0"><i class="bi bi-clock-history"></i> Recent Orders</h5>
                <a href="<?php echo e(route('orders.index')); ?>" class="btn btn-sm btn-outline-primary">View All</a>
            </div>
            <div class="card-body pt-0">
                <?php $__empty_1 = true; $__currentLoopData = $recentOrders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <div class="recent-order-item">
                    <div class="d-flex justify-content-between align-items-start">
                        <div>
                            <a href="<?php echo e(route('orders.show', $order)); ?>" class="text-decoration-none fw-semibold">
                                <?php echo e($order->invoice_number); ?>

                            </a>
                            <div class="small text-muted">
                                <?php echo e($order->customer?->name ?? 'Walk-in Customer'); ?>

                            </div>
                        </div>
                        <div class="text-end">
                            <div class="fw-bold">Kes <?php echo e(number_format($order->total, 0)); ?></div>
                            <small class="text-muted"><?php echo e($order->created_at->format('H:i')); ?></small>
                        </div>
                    </div>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="text-center text-muted py-4">
                    <i class="bi bi-inbox fs-1 d-block mb-2"></i>
                    No recent orders
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<div class="row g-4 mt-2">
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-header bg-transparent border-0 pt-3">
                <h5 class="section-title mb-0"><i class="bi bi-trophy-fill"></i> Top Products (This Month)</h5>
            </div>
            <div class="card-body pt-0">
                <?php $__empty_1 = true; $__currentLoopData = $topProducts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <div class="top-product-item d-flex align-items-center py-2 <?php echo e(!$loop->last ? 'border-bottom' : ''); ?>">
                    <div class="rank me-3 <?php echo e($index === 0 ? 'bg-warning text-dark' : ($index === 1 ? 'bg-secondary text-white' : ($index === 2 ? 'text-white' : 'bg-light text-muted'))); ?>" <?php if($index === 2): ?> style="background-color: #cd7f32;" <?php endif; ?>>
                        <?php echo e($index + 1); ?>

                    </div>
                    <div class="flex-grow-1">
                        <div class="fw-semibold"><?php echo e($product->name); ?></div>
                        <small class="text-muted"><?php echo e(number_format($product->total_sold)); ?> units sold</small>
                    </div>
                    <span class="badge bg-primary rounded-pill"><?php echo e(number_format($product->total_sold)); ?></span>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="text-center text-muted py-4">
                    <i class="bi bi-bar-chart fs-1 d-block mb-2"></i>
                    No sales data yet
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-header bg-transparent border-0 pt-3">
                <h5 class="section-title mb-0"><i class="bi bi-exclamation-triangle-fill text-danger"></i> Overdue Credits</h5>
            </div>
            <div class="card-body pt-0">
                <?php $__empty_1 = true; $__currentLoopData = $overdueOrders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <div class="recent-order-item">
                    <div class="d-flex justify-content-between align-items-start">
                        <div>
                            <a href="<?php echo e(route('orders.show', $order)); ?>" class="text-decoration-none fw-semibold">
                                <?php echo e($order->invoice_number); ?>

                            </a>
                            <div class="small text-muted">
                                <?php echo e($order->customer?->name ?? 'N/A'); ?>

                                <?php if($order->due_date): ?>
                                    <span class="ms-2">
                                        Due: <?php echo e($order->due_date->format('M d')); ?>

                                        <?php if($order->due_date->lt(now())): ?>
                                            <span class="badge bg-danger ms-1"><?php echo e(now()->diffInDays($order->due_date)); ?>d late</span>
                                        <?php endif; ?>
                                    </span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="text-end">
                            <div class="fw-bold text-danger">Kes <?php echo e(number_format($order->credit_balance, 0)); ?></div>
                            <span class="badge bg-<?php echo e($order->credit_status === 'overdue' ? 'danger' : 'warning'); ?>">
                                <?php echo e(ucfirst($order->credit_status)); ?>

                            </span>
                        </div>
                    </div>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="text-center text-muted py-4">
                    <i class="bi bi-check-circle fs-1 d-block mb-2 text-success"></i>
                    No overdue credits
                </div>
                <?php endif; ?>
                <?php if($overdueOrders->count() > 0): ?>
                <div class="mt-3">
                    <a href="<?php echo e(route('credit.index')); ?>" class="btn btn-sm btn-outline-danger w-100">
                        View All Overdue <i class="bi bi-arrow-right ms-1"></i>
                    </a>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\AI PROJECT POS\PosAI3\resources\views/dashboard/index.blade.php ENDPATH**/ ?>