@extends('layouts.admin')

@section('title', 'Gestion des Badges')

@section('content')
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0">Gestion des Badges</h1>
        <div>
            <form action="{{ route('admin.badges.recalculate') }}" method="POST" class="d-inline">
                @csrf
                <button type="submit" class="btn btn-warning">Recalculer tous les badges</button>
            </form>
            <a href="{{ route('admin.badges.create') }}" class="btn btn-primary">+ Nouveau Badge</a>
        </div>
    </div>

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

    <div class="row">
        @forelse($badges as $badge)
        <div class="col-md-4 mb-4">
            <div class="card h-100">
                <div class="card-header d-flex justify-content-between align-items-center" style="background-color: {{ $badge->color ?? '#6c757d' }}20;">
                    <span class="badge" style="background-color: {{ $badge->color ?? '#6c757d' }}">
                        {{ $badge->name }}
                    </span>
                    @if(!$badge->is_active)
                        <span class="badge bg-secondary">Inactif</span>
                    @endif
                </div>
                <div class="card-body">
                    <p class="text-muted">{{ $badge->description ?? 'Pas de description' }}</p>
                    <p><strong>Type:</strong> {{ $badge->type }}</p>
                    <p><strong>Points:</strong> {{ $badge->points_value ?? 0 }}</p>
                    <p><strong>Utilisateurs:</strong> {{ $badge->users_count }}</p>
                </div>
                <div class="card-footer d-flex gap-2">
                    <a href="{{ route('admin.badges.edit', $badge) }}" class="btn btn-sm btn-outline-primary">Modifier</a>
                    <form action="{{ route('admin.badges.toggle', $badge) }}" method="POST">
                        @csrf
                        <button type="submit" class="btn btn-sm {{ $badge->is_active ? 'btn-warning' : 'btn-success' }}">
                            {{ $badge->is_active ? 'Désactiver' : 'Activer' }}
                        </button>
                    </form>
                    <form action="{{ route('admin.badges.destroy', $badge) }}" method="POST" onsubmit="return confirm('Supprimer ce badge?')">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
                    </form>
                </div>
            </div>
        </div>
        @empty
        <div class="col-12">
            <div class="alert alert-info">Aucun badge configuré</div>
        </div>
        @endforelse
    </div>
</div>
@endsection
