@extends('admin.layouts.app')

@section('title', 'Categories')
@section('page-title', 'Categories')

@section('content')
<div class="mb-4 md:mb-6">
    <a href="{{ route('admin.categories.create') }}" class="w-full sm:w-auto bg-black text-white px-4 md:px-6 py-2 md:py-3 rounded-xl hover:bg-[#1a1a1a] transition-all font-semibold shadow-md hover:shadow-lg flex items-center justify-center gap-2 text-sm md:text-base">
        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
        </svg>
        Add New Category
    </a>
</div>

<!-- Mobile Card View -->
<div id="categories-mobile-container" class="lg:hidden space-y-4">
    @include('admin.categories.partials.mobile-cards', ['categories' => $categories])
</div>

<!-- Desktop Table View -->
<div class="hidden lg:block bg-white rounded-2xl shadow-md border border-[#d1d5db] overflow-x-auto">
    <table class="w-full">
        <thead class="bg-[#f3f4f6] border-b border-[#d1d5db]">
            <tr>
                <th class="px-4 xl:px-6 py-3 md:py-4 text-left text-black font-semibold text-sm md:text-base">Image</th>
                <th class="px-4 xl:px-6 py-3 md:py-4 text-left text-black font-semibold text-sm md:text-base">Name</th>
                <th class="px-4 xl:px-6 py-3 md:py-4 text-left text-black font-semibold text-sm md:text-base hidden xl:table-cell">Description</th>
                <th class="px-4 xl:px-6 py-3 md:py-4 text-left text-black font-semibold text-sm md:text-base">Products</th>
                <th class="px-4 xl:px-6 py-3 md:py-4 text-left text-black font-semibold text-sm md:text-base">Actions</th>
            </tr>
        </thead>
        <tbody>
            @forelse($categories as $category)
                <tr class="border-b border-[#d1d5db] hover:bg-[#f3f4f6] transition-colors">
                    <td class="px-4 xl:px-6 py-3 md:py-4">
                        @if($category->image_base64)
                            <img src="{{ $category->image_data_url }}" alt="{{ $category->name }}" class="w-12 h-12 md:w-16 md:h-16 object-cover rounded-lg border border-[#d1d5db]">
                        @else
                            <div class="w-12 h-12 md:w-16 md:h-16 bg-gradient-to-br from-[#d1d5db] to-[#e6d5b8] rounded-lg border border-[#d1d5db]"></div>
                        @endif
                    </td>
                    <td class="px-4 xl:px-6 py-3 md:py-4 text-black font-medium text-sm md:text-base">{{ $category->name }}</td>
                    <td class="px-4 xl:px-6 py-3 md:py-4 text-black text-sm md:text-base hidden xl:table-cell">{{ \Illuminate\Support\Str::limit($category->description, 50) }}</td>
                    <td class="px-4 xl:px-6 py-3 md:py-4 text-black font-semibold text-sm md:text-base">{{ $category->products_count }}</td>
                    <td class="px-4 xl:px-6 py-3 md:py-4">
                        <div class="flex flex-wrap gap-2 md:gap-3">
                            <a href="{{ route('admin.categories.edit', $category->id) }}" class="text-black hover:text-black transition-colors font-medium text-xs md:text-sm">Edit</a>
                            <form method="POST" action="{{ route('admin.categories.destroy', $category->id) }}" onsubmit="return confirm('Are you sure?')" class="inline">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="text-black hover:text-[#b86a4f] transition-colors font-medium text-xs md:text-sm">Delete</button>
                            </form>
                        </div>
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="5" class="px-4 md:px-6 py-8 md:py-12 text-center text-black text-sm md:text-base">
                        <p class="text-base md:text-lg">No categories found.</p>
                        <a href="{{ route('admin.categories.create') }}" class="text-black hover:text-black transition-colors mt-2 inline-block text-sm md:text-base">Create your first category</a>
                    </td>
                </tr>
            @endforelse
        </tbody>
    </table>
</div>

<div class="mt-4 md:mt-6">
    {{ $categories->links() }}
</div>
@endsection


