@extends('layouts.admin')

@section('title', 'Paramètres épargne')

@push('styles')
<style>
    body { background: #f5f7fb; color: #1f2937; }
    .glass-card { background: #ffffff; border-radius: 20px; border: 1px solid #e5e7eb; box-shadow: 0 10px 30px rgba(15,23,42,0.08); }
    .btn-glass { background: #0f172a; border: 1px solid #0f172a; color: #ffffff; transition: all 0.2s; }
    .btn-glass:hover { background: #111827; color: #ffffff; }
    .text-white { color: #0f172a !important; }
    .text-white-70 { color: #475569 !important; }
</style>
@endpush

@section('content')
@php
    $pendingUnlocks = \App\Models\UnlockRequest::where('status', 'pending')->count();
    $penaltyRate = \App\Models\Setting::get('savings_unlock_penalty_rate', 0);
@endphp
<div class="container-fluid py-5">
    @if(session('success'))
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        ✅ {{ session('success') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    @endif

    @if(session('error'))
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        ❌ {{ session('error') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    @endif

    <div class="glass-card p-4 mb-4">
        <h1 class="text-white fw-bold mb-2">⚙️ Paramètres Épargne</h1>
        <p class="text-white-70 mb-0">Configurer les règles de déblocage et pénalités</p>
    </div>

    <div class="glass-card p-4 mb-4">
        <ul class="nav nav-pills nav-fill">
            <li class="nav-item"><a class="nav-link btn-glass mx-1" href="{{ route('admin.savings.index') }}">🏠 Dashboard</a></li>
            <li class="nav-item"><a class="nav-link btn-glass mx-1" href="{{ route('admin.savings.plans') }}">📊 Plans</a></li>
            <li class="nav-item"><a class="nav-link btn-glass mx-1" href="{{ route('admin.savings.unlock-requests') }}">🔓 Demandes @if($pendingUnlocks > 0)<span class="badge bg-danger ms-1">{{ $pendingUnlocks }}</span>@endif</a></li>
            <li class="nav-item"><a class="nav-link btn-glass mx-1 active" href="{{ route('admin.savings.settings') }}">⚙️ Paramètres</a></li>
        </ul>
    </div>

    <div class="glass-card p-5">
        <h4 class="text-white fw-bold mb-3">Pénalité de déblocage anticipé</h4>
        <form action="{{ route('admin.savings.update-settings') }}" method="POST" class="row g-3 align-items-center">
            @csrf
            <div class="col-md-6">
                <label class="form-label text-white">Taux de pénalité (%)</label>
                <input type="number" name="savings_unlock_penalty_rate" class="form-control" step="0.1" min="0" max="50" value="{{ $penaltyRate }}" required>
                <small class="text-white-70">Montant retenu lors d'un déblocage anticipé.</small>
            </div>
            <div class="col-md-12">
                <button type="submit" class="btn btn-primary mt-2"><i class="fas fa-save me-2"></i>Enregistrer</button>
            </div>
        </form>
    </div>
</div>
@endsection
