@extends('admin.layouts.app')
@section('title', 'Categories')
@section('content')
<div class="page-header d-print-none">
    <div class="container-xl">
        <div class="row g-2 align-items-center">
            <div class="col"><h2 class="page-title">Categories</h2></div>
            <div class="col-auto"><a href="{{ route('admin.categories.create') }}" class="btn btn-primary">+ Add Category</a></div>
        </div>
    </div>
</div>
<div class="page-body">
    <div class="card mb-3">
        <div class="card-body">
            <form method="GET" class="row g-3">
                <div class="col-md-4">
                    <select name="type" class="form-select">
                        <option value="">All Types</option>
                        @foreach(['ride','food','delivery','freelance'] as $t)
                            <option value="{{ $t }}" {{ request('type')==$t?'selected':'' }}>{{ ucfirst($t) }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-4 d-flex gap-2">
                    <button type="submit" class="btn btn-primary">Filter</button>
                    <a href="{{ route('admin.categories.index') }}" class="btn btn-outline-secondary">Clear</a>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="card-header"><h3 class="card-title">All Categories ({{ $categories->total() }})</h3></div>
        <div class="table-responsive">
            <table class="table table-vcenter card-table">
                <thead>
                    <tr><th>Name</th><th>Type</th><th>Vendors</th><th>Status</th><th>Actions</th></tr>
                </thead>
                <tbody>
                    @forelse($categories as $category)
                    <tr>
                        <td>
                            <div class="d-flex align-items-center gap-2">
                                @if($category->icon)<span class="text-muted">{{ $category->icon }}</span>@endif
                                <div class="fw-medium">{{ $category->name }}</div>
                            </div>
                        </td>
                        <td><span class="badge bg-blue-lt text-capitalize">{{ $category->type }}</span></td>
                        <td>{{ $category->vendors_count }}</td>
                        <td>
                            <span class="badge bg-{{ $category->is_active?'success':'secondary' }}-lt">
                                {{ $category->is_active ? 'Active' : 'Disabled' }}
                            </span>
                        </td>
                        <td>
                            <div class="d-flex gap-1">
                                <a href="{{ route('admin.categories.edit', $category) }}" class="btn btn-sm btn-outline-secondary">Edit</a>
                                <form action="{{ route('admin.categories.toggle', $category) }}" method="POST">
                                    @csrf
                                    <button class="btn btn-sm btn-{{ $category->is_active?'warning':'success' }}">
                                        {{ $category->is_active ? 'Disable' : 'Enable' }}
                                    </button>
                                </form>
                                <form action="{{ route('admin.categories.destroy', $category) }}" method="POST">
                                    @csrf @method('DELETE')
                                    <button class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this category?')">Delete</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="5" class="text-center text-muted py-4">No categories found</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="card-footer d-flex align-items-center">{{ $categories->links() }}</div>
    </div>
</div>
@endsection
