@extends('user.layouts.master')

@section('main-content')
<div class="container-fluid">

    <h4 class="mb-4 font-weight-bold">My Dashboard</h4>

    {{-- STATS CARDS --}}
    <div class="row">

        {{-- TOTAL ORDERS --}}
        <div class="col-md-4 mb-4">
            <div class="card shadow-sm border-left-primary h-100">
                <div class="card-body d-flex justify-content-between">
                    <div>
                        <div class="text-xs text-primary font-weight-bold text-uppercase">
                            Total Orders
                        </div>
                        <div class="h4 font-weight-bold">
                            {{ $totalOrders }}
                        </div>
                    </div>
                    <div class="text-primary">
                        <i class="fas fa-shopping-bag fa-2x"></i>
                    </div>
                </div>
            </div>
        </div>

        {{-- TOTAL SPENT --}}
        <div class="col-md-4 mb-4">
            <div class="card shadow-sm border-left-success h-100">
                <div class="card-body d-flex justify-content-between">
                    <div>
                        <div class="text-xs text-success font-weight-bold text-uppercase">
                            Total Spent
                        </div>
                        <div class="h4 font-weight-bold">
                            ₹{{ number_format($totalSpent,2) }}
                        </div>
                    </div>
                    <div class="text-success">
                        <i class="fas fa-rupee-sign fa-2x"></i>
                    </div>
                </div>
            </div>
        </div>

        {{-- PENDING --}}
        <div class="col-md-4 mb-4">
            <div class="card shadow-sm border-left-warning h-100">
                <div class="card-body d-flex justify-content-between">
                    <div>
                        <div class="text-xs text-warning font-weight-bold text-uppercase">
                            Active Orders
                        </div>
                        <div class="h4 font-weight-bold">
                            {{ $pendingOrders }}
                        </div>
                    </div>
                    <div class="text-warning">
                        <i class="fas fa-clock fa-2x"></i>
                    </div>
                </div>
            </div>
        </div>

    </div>

    {{-- RECENT ORDERS --}}
    <div class="card shadow-sm">
        <div class="card-header bg-light d-flex justify-content-between">
            <strong>Recent Orders</strong>
            <a href="{{ route('user.order.index') }}" class="btn btn-sm btn-primary">
                View All
            </a>
        </div>

        <div class="card-body">

            @forelse($orders as $order)
                <div class="border rounded p-3 mb-3">

                    <div class="d-flex justify-content-between">
                        <div>
                            <strong>Order #{{ $order->order_number }}</strong><br>
                            <small class="text-muted">
                                {{ $order->created_at->format('d M Y, h:i A') }}
                            </small>
                        </div>

                        <div class="text-right">
                            <div class="font-weight-bold">
                                ₹{{ number_format($order->total_amount,2) }}
                            </div>
                            <span class="badge badge-info text-uppercase">
                                {{ $order->status }}
                            </span>
                        </div>
                    </div>

                    <hr class="my-2">

                    <div class="d-flex justify-content-between small text-muted">
                        <div>
                            Payment: {{ ucfirst($order->payment_method) }} |
                            {{ ucfirst($order->payment_status) }}
                        </div>
                        <div>
                            <a href="{{ route('user.order.show',$order->id) }}">
                                View Details →
                            </a>
                        </div>
                    </div>

                </div>
            @empty
                <div class="text-center py-4">
                    <h6>No orders yet</h6>
                    <a href="{{ route('product-grids') }}" class="btn btn-primary btn-sm mt-2">
                        Start Shopping
                    </a>
                </div>
            @endforelse

        </div>
    </div>

</div>
@endsection