@extends('eliteadmin::layouts.app')

@section('title', 'Income Categories')

@section('content')
    <div class="page-header d-flex justify-content-between align-items-start flex-wrap gap-2">
        <div>
            <h1 class="page-title">Income Categories</h1>
        </div>
        @can('finance.categories.manage')
            <a href="{{ route('finance.income-categories.create') }}" class="btn btn-primary btn-sm">Add Category</a>
        @endcan
    </div>

    <form method="GET" class="row g-2 mb-3">
        <div class="col-md-4"><input type="text" name="search" value="{{ request('search') }}" class="form-control" placeholder="Search categories"></div>
        <div class="col-md-2"><button class="btn btn-outline-primary">Search</button></div>
    </form>

    <div class="card">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light"><tr><th>Name</th><th>Status</th><th class="text-end">Actions</th></tr></thead>
                <tbody>
                    @forelse ($categories as $category)
                        <tr>
                            <td><strong>{{ $category->name }}</strong><div class="small text-muted">{{ $category->description }}</div></td>
                            <td><span class="badge bg-{{ $category->is_active ? 'success' : 'secondary' }}">{{ $category->is_active ? 'Active' : 'Inactive' }}</span></td>
                            <td class="text-end">
                                @can('finance.categories.manage')
                                    <a href="{{ route('finance.income-categories.edit', $category) }}" class="btn btn-sm btn-outline-primary">Edit</a>
                                @endcan
                                @can('finance.categories.manage')
                                    <form action="{{ route('finance.income-categories.destroy', $category) }}" method="POST" class="d-inline" onsubmit="return confirm('Delete this category?')">
                                        @csrf @method('DELETE')
                                        <button class="btn btn-sm btn-outline-danger">Delete</button>
                                    </form>
                                @endcan
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="3" class="text-center text-muted py-4">No categories found</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if ($categories->hasPages())
            <div class="card-footer">{{ $categories->links() }}</div>
        @endif
    </div>
@endsection
