@extends('layouts.app')

@section('content')
<div class="container mx-auto py-8">
    <div class="mb-6">
        <h1 class="text-3xl font-bold">Our Products</h1>
        <p class="text-gray-600">Browse our collection of quality products</p>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-6">
        @forelse($products as $product)
        <div class="bg-white rounded-lg shadow hover:shadow-lg transition">
            <div class="aspect-square bg-gray-200 rounded-t-lg overflow-hidden">
                @if($product->image)
                <img src="{{ asset('storage/' . $product->image) }}" alt="{{ $product->name }}" class="w-full h-full object-cover">
                @else
                <div class="w-full h-full flex items-center justify-center text-4xl">📦</div>
                @endif
            </div>
            <div class="p-4">
                <h3 class="font-semibold text-lg mb-2">{{ $product->name }}</h3>
                <p class="text-gray-600 text-sm mb-4">{{ Str::limit($product->description, 50) }}</p>
                <div class="flex justify-between items-center">
                    <span class="text-xl font-bold text-blue-600">${{ number_format($product->price, 2) }}</span>
                    <form action="{{ route('cart.add') }}" method="POST" class="inline">
                        @csrf
                        <input type="hidden" name="product_id" value="{{ $product->id }}">
                        <input type="hidden" name="quantity" value="1">
                        <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
                            Add to Cart
                        </button>
                    </form>
                </div>
            </div>
        </div>
        @empty
        <div class="col-span-full text-center py-12">
            <p class="text-gray-500 text-lg">No products available</p>
        </div>
        @endforelse
    </div>

    <div class="mt-8">
        {{ $products->links() }}
    </div>
</div>
@endsection
