<div>
    <!-- Page Header -->
    <div class="page-header">
        <h1 class="page-title">{{ __('Dashboard') }}</h1>
        <p class="text-muted">{{ __('Welcome back') }}, {{ auth()->user()->name }}!</p>
    </div>

    <!-- Stats Row -->
    <div class="row g-4 mb-4">
        <!-- Today's Sales -->
        <div class="col-sm-6 col-xl-3">
            <div class="stat-widget">
                <div class="stat-icon bg-primary text-white">
                    <i class="fas fa-shopping-cart"></i>
                </div>
                <div class="stat-content">
                    <div class="stat-value">E£ {{ number_format($todaysSales, 2) }}</div>
                    <div class="stat-label">{{ __("Today's Sales") }}</div>
                </div>
            </div>
        </div>

        <!-- Products Sold -->
        <div class="col-sm-6 col-xl-3">
            <div class="stat-widget">
                <div class="stat-icon bg-success text-white">
                    <i class="fas fa-box"></i>
                </div>
                <div class="stat-content">
                    <div class="stat-value">{{ number_format($productsSold) }}</div>
                    <div class="stat-label">{{ __('Products Sold') }}</div>
                </div>
            </div>
        </div>

        <!-- Customers -->
        <div class="col-sm-6 col-xl-3">
            <div class="stat-widget">
                <div class="stat-icon bg-info text-white">
                    <i class="fas fa-users"></i>
                </div>
                <div class="stat-content">
                    <div class="stat-value">{{ number_format($totalCustomers) }}</div>
                    <div class="stat-label">{{ __('Total Customers') }}</div>
                </div>
            </div>
        </div>

        <!-- Low Stock -->
        <div class="col-sm-6 col-xl-3">
            <div class="stat-widget">
                <div class="stat-icon bg-warning text-white">
                    <i class="fas fa-exclamation-triangle"></i>
                </div>
                <div class="stat-content">
                    <div class="stat-value">{{ number_format($lowStockItems) }}</div>
                    <div class="stat-label">{{ __('Low Stock Items') }}</div>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-4">
        <!-- Recent Sales -->
        <div class="col-xl-8">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">{{ __('Recent Sales') }}</h5>
                    <a href="{{ route('sales.index') }}" class="btn btn-sm btn-outline-primary">
                        {{ __('View All') }}
                    </a>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>{{ __('Invoice #') }}</th>
                                    <th>{{ __('Customer') }}</th>
                                    <th>{{ __('Date') }}</th>
                                    <th>{{ __('Amount') }}</th>
                                    <th>{{ __('Status') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($recentSales as $sale)
                                <tr>
                                    <td>{{ $sale->sale_number }}</td>
                                    <td>
                                        @if($sale->partner)
                                            {{ $sale->partner->name }}
                                        @else
                                            <span class="text-muted">{{ __('Walk-in Customer') }}</span>
                                        @endif
                                    </td>
                                    <td>{{ $sale->created_at->format('Y-m-d H:i') }}</td>
                                    <td>E£ {{ number_format($sale->total, 2) }}</td>
                                    <td>
                                        <span class="badge bg-{{ $sale->status === 'completed' ? 'success' : ($sale->status === 'pending' ? 'warning' : 'secondary') }}">
                                            {{ ucfirst(__($sale->status)) }}
                                        </span>
                                    </td>
                                </tr>
                                @empty
                                <tr>
                                    <td colspan="5" class="text-center text-muted py-4">
                                        <i class="fas fa-inbox fa-3x mb-3 d-block opacity-50"></i>
                                        {{ __('No recent sales') }}
                                    </td>
                                </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div class="col-xl-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">{{ __('Quick Actions') }}</h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-3">
                        <a href="{{ route('pos.index') }}" class="btn btn-primary btn-lg">
                            <i class="fas fa-cash-register me-2"></i>{{ __('Open POS') }}
                        </a>
                        <a href="{{ route('products.index') }}" class="btn btn-outline-primary">
                            <i class="fas fa-plus me-2"></i>{{ __('Add Product') }}
                        </a>
                        <a href="{{ route('partners.create') }}" class="btn btn-outline-primary">
                            <i class="fas fa-user-plus me-2"></i>{{ __('Add Partner') }}
                        </a>
                        <a href="{{ route('purchases.index') }}" class="btn btn-outline-primary">
                            <i class="fas fa-truck me-2"></i>{{ __('Create PO') }}
                        </a>
                    </div>
                </div>
            </div>

            <!-- Low Stock Alert -->
            <div class="card mt-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">{{ __('Low Stock Alert') }}</h5>
                    <span class="badge bg-{{ $lowStockItems > 0 ? 'danger' : 'success' }}">{{ $lowStockItems }}</span>
                </div>
                <div class="card-body">
                    @if($lowStockItems > 0)
                        <div class="text-center text-danger py-3">
                            <i class="fas fa-exclamation-circle fa-2x mb-2"></i>
                            <p class="mb-0">{{ $lowStockItems }} {{ __('products are low on stock') }}</p>
                            <a href="{{ route('inventory.low-stock') }}" class="btn btn-sm btn-link mt-2">{{ __('View Low Stock Items') }}</a>
                        </div>
                    @else
                        <div class="text-center text-success py-3">
                            <i class="fas fa-check-circle fa-2x mb-2"></i>
                            <p class="mb-0">{{ __('All products are well stocked') }}</p>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>


</div>
