@extends('layouts.master')
@section('title', 'Groups')

@section('content')
<div class="container mt-4">
    <div class="d-flex justify-content-end mb-2">
        <a href="{{ route('groups.create') }}" class="btn btn-primary mb-1"> Add Group</a>
    </div>
    <div class="card-header bg-primary text-white py-3">
        <h5 class="mb-0"><i class="fas fa-layer-group me-2"></i>Groups</h5>
    </div>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>#</th>
                <th>Group Name</th>
                <th>Description</th>
                <th width="180px">Actions</th>
            </tr>
        </thead>
        <tbody>
            @forelse($groups as $group)
                <tr>
                    <td>{{ $loop->iteration }}</td>
                    <td>{{ $group->name }}</td>
                    <td>{{ $group->description }}</td>
                    <td>
                        <a href="{{ route('groups.edit', $group) }}" class="btn btn-secondary btn-sm">Edit</a>
                        <form action="{{ route('groups.destroy', $group) }}" method="POST" style="display:inline;">
                            @csrf @method('DELETE')
                            <button type="submit" class="btn btn-danger btn-sm"
                                onclick="return confirm('Are you sure?')">Delete</button>
                        </form>
                    </td>
                </tr>
            @empty
                <tr><td colspan="4">No groups found.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>
@endsection
