@extends('layouts.admin')
@section('title', 'Admin Dashboard Overview')
@section('header_title', 'Dashboard Overview')

@section('content')
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
    {{-- Stat Card 1 --}}
    <div class="bg-white rounded-lg border border-gray-200 p-6 shadow-sm relative overflow-hidden group">
        <div class="absolute right-0 top-0 w-24 h-24 bg-brand-red/5 rounded-bl-full -mr-8 -mt-8 transition-transform group-hover:scale-110"></div>
        <div class="flex justify-between items-start mb-4 relative z-10">
            <div>
                <p class="text-gray-500 text-xs font-bold uppercase tracking-widest mb-1">Total Products</p>
                <h3 class="text-4xl font-extrabold text-brand-dark">{{ number_format($productsCount) }}</h3>
            </div>
            <div class="w-12 h-12 bg-red-50 text-brand-red rounded-lg flex items-center justify-center"><i data-lucide="package" class="w-6 h-6"></i></div>
        </div>
        <div class="text-sm border-t border-gray-100 pt-3 relative z-10"><a href="{{ route('admin.products.index') }}" class="text-brand-red font-bold hover:underline">Manage Products &rarr;</a></div>
    </div>

    {{-- Stat Card 2 --}}
    <div class="bg-white rounded-lg border border-gray-200 p-6 shadow-sm relative overflow-hidden group">
        <div class="absolute right-0 top-0 w-24 h-24 bg-blue-50 rounded-bl-full -mr-8 -mt-8 transition-transform group-hover:scale-110"></div>
        <div class="flex justify-between items-start mb-4 relative z-10">
            <div>
                <p class="text-gray-500 text-xs font-bold uppercase tracking-widest mb-1">Total Customers</p>
                <h3 class="text-4xl font-extrabold text-brand-dark">{{ number_format($usersCount) }}</h3>
            </div>
            <div class="w-12 h-12 bg-blue-50 text-blue-600 rounded-lg flex items-center justify-center"><i data-lucide="users" class="w-6 h-6"></i></div>
        </div>
        <div class="text-sm text-gray-500 border-t border-gray-100 pt-3 relative z-10"><span class="text-green-500 font-bold">&uarr; 12%</span> from last month</div>
    </div>

    {{-- Stat Card 3 --}}
    <div class="bg-white rounded-lg border border-gray-200 p-6 shadow-sm relative overflow-hidden group">
        <div class="absolute right-0 top-0 w-24 h-24 bg-green-50 rounded-bl-full -mr-8 -mt-8 transition-transform group-hover:scale-110"></div>
        <div class="flex justify-between items-start mb-4 relative z-10">
            <div>
                <p class="text-gray-500 text-xs font-bold uppercase tracking-widest mb-1">Total Orders</p>
                <h3 class="text-4xl font-extrabold text-brand-dark">0</h3>
            </div>
            <div class="w-12 h-12 bg-green-50 text-green-600 rounded-lg flex items-center justify-center"><i data-lucide="shopping-cart" class="w-6 h-6"></i></div>
        </div>
        <div class="text-sm text-gray-500 border-t border-gray-100 pt-3 relative z-10"><span class="text-gray-400 font-bold">Waiting for orders</span></div>
    </div>
</div>

{{-- Recent Products Section --}}
<div class="bg-white rounded-lg border border-gray-200 shadow-sm">
    <div class="px-6 py-4 border-b border-gray-200 flex justify-between items-center">
        <h3 class="font-extrabold text-brand-dark uppercase tracking-wider">Recently Added Products</h3>
        <a href="{{ route('admin.products.create') }}" class="text-xs font-bold text-white bg-brand-red px-3 py-1.5 rounded uppercase tracking-widest hover:bg-black transition-colors">Add New</a>
    </div>
    <div class="overflow-x-auto">
        <table class="w-full text-left text-sm whitespace-nowrap">
            <thead class="bg-gray-50 border-b border-gray-200 text-gray-500">
                <tr>
                    <th class="px-6 py-3 font-bold uppercase tracking-wider text-xs">Product</th>
                    <th class="px-6 py-3 font-bold uppercase tracking-wider text-xs">Category</th>
                    <th class="px-6 py-3 font-bold uppercase tracking-wider text-xs">Price</th>
                    <th class="px-6 py-3 font-bold uppercase tracking-wider text-xs">Stock</th>
                    <th class="px-6 py-3 font-bold uppercase tracking-wider text-xs">Added</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                @if($recentProducts->count() > 0)
                    @foreach($recentProducts as $product)
                    <tr class="hover:bg-gray-50 transition-colors">
                        <td class="px-6 py-4">
                            <div class="flex items-center space-x-3">
                                <div class="w-10 h-10 bg-white border border-gray-100 rounded overflow-hidden flex-shrink-0">
                                    @if($product->image_path)
                                        <img src="{{ asset('images/' . $product->image_path) }}" class="w-full h-full object-cover">
                                    @else
                                        <div class="w-full h-full bg-gray-100 flex items-center justify-center text-gray-400"><i data-lucide="image" class="w-4 h-4"></i></div>
                                    @endif
                                </div>
                                <div class="font-bold text-gray-800 truncate max-w-[200px]">{{ $product->name }}</div>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-gray-600">{{ $product->category }}</td>
                        <td class="px-6 py-4 font-bold text-brand-dark">${{ number_format($product->price, 2) }}</td>
                        <td class="px-6 py-4">
                            <span class="px-2 py-1 rounded text-xs font-bold {{ $product->stock > 0 ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700' }}">
                                {{ $product->stock }}
                            </span>
                        </td>
                        <td class="px-6 py-4 text-gray-500">{{ $product->created_at->diffForHumans() }}</td>
                    </tr>
                    @endforeach
                @else
                <tr>
                    <td colspan="5" class="px-6 py-8 text-center text-gray-500">No products found.</td>
                </tr>
                @endif
            </tbody>
        </table>
    </div>
</div>
@endsection
