@extends('admin.layouts.app')
@section('title', 'Categories')
@section('content')
<div class="action-bar">
    <span>{{ $categories->total() }} categories</span>
    <a href="{{ route('admin.categories.create') }}" class="btn btn-primary">+ New Category</a>
</div>
<div class="card">
    <table>
        <tr><th>Name</th><th>Slug</th><th>Parent</th><th>Products</th><th>Order</th><th>Active</th><th>Actions</th></tr>
        @foreach($categories as $category)
        <tr>
            <td><strong>{{ $category->name }}</strong></td>
            <td class="text-muted">{{ $category->slug }}</td>
            <td>{{ $category->parent->name ?? '—' }}</td>
            <td>{{ $category->products->count() }}</td>
            <td>{{ $category->order }}</td>
            <td>{!! $category->is_active ? '<span style="color:#6fcf97">Yes</span>' : '<span style="color:#e74c3c">No</span>' !!}</td>
            <td class="inline-flex">
                <a href="{{ route('admin.categories.edit', $category) }}" class="btn btn-primary btn-sm">Edit</a>
                <form action="{{ route('admin.categories.destroy', $category) }}" method="POST" onsubmit="return confirm('Delete this category?')">
                    @csrf @method('DELETE')
                    <button type="submit" class="btn btn-danger btn-sm">Delete</button>
                </form>
            </td>
        </tr>
        @endforeach
    </table>
    <div class="pagination">{{ $categories->links() }}</div>
</div>
@endsection
