@extends('layouts.admin')

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

@section('content')
<div class="bg-white rounded-xl shadow-sm p-6">
    <div class="flex justify-end mb-4">
        <a href="{{ route('admin.categories.create') }}" class="bg-red-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-red-700">+ Add Category</a>
    </div>
    <table class="w-full text-sm">
        <thead>
            <tr class="text-gray-500 border-b bg-gray-50">
                <th class="text-left p-3">Name</th>
                <th class="text-left p-3">Products</th>
                <th class="text-left p-3">Status</th>
                <th class="text-left p-3">Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach($categories as $category)
            <tr class="border-b hover:bg-gray-50">
                <td class="p-3 font-medium">{{ $category->name }}</td>
                <td class="p-3">{{ $category->products_count ?? 0 }}</td>
                <td class="p-3">
                    <span class="px-2 py-0.5 rounded-full text-xs {{ $category->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600' }}">
                        {{ $category->is_active ? 'Active' : 'Inactive' }}
                    </span>
                </td>
                <td class="p-3 flex gap-2">
                    <a href="{{ route('admin.categories.edit', $category->id) }}" class="text-xs bg-blue-600 text-white px-2 py-1 rounded hover:bg-blue-700">Edit</a>
                    <form action="{{ route('admin.categories.destroy', $category->id) }}" method="POST" onsubmit="return confirm('Delete?')">
                        @csrf @method('DELETE')
                        <button class="text-xs bg-red-600 text-white px-2 py-1 rounded hover:bg-red-700">Delete</button>
                    </form>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @if(isset($categories) && method_exists($categories, 'links'))
    <div class="mt-4">{{ $categories->links() }}</div>
    @endif
</div>
@endsection
