@extends('layouts.admin')

@section('title', 'Plans d\'investissement')
@section('page-title', 'Plans d\'investissement (Admin)')

@section('content')
<div class="container-fluid">
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Plans d'investissement</h1>
        <a href="{{ route('admin.investment-categories.index') }}" class="btn btn-sm btn-primary">Gérer les catégories</a>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    @endif

    <div class="row">
        <div class="col-lg-12">
            <div class="card shadow mb-4">
                <div class="card-header py-3 d-flex justify-content-between align-items-center">
                    <h6 class="m-0 font-weight-bold text-primary">Catégories & produits</h6>
                    <a href="{{ route('admin.investment-products.create') }}" class="btn btn-sm btn-success">Ajouter un produit</a>
                </div>
                <div class="card-body">
                    @forelse($categories as $category)
                        <div class="mb-4">
                            <div class="d-flex justify-content-between align-items-center mb-2">
                                <div>
                                    <h5 class="mb-0">{{ $category->name }}</h5>
                                    <small class="text-muted">Ordre: {{ $category->order }} | Statut: {{ $category->is_active ? 'Actif' : 'Inactif' }}</small>
                                </div>
                                <div>
                                    <a href="{{ route('admin.investment-categories.edit', $category->id) }}" class="btn btn-sm btn-outline-primary">Modifier</a>
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-sm table-hover">
                                    <thead>
                                        <tr>
                                            <th>Produit</th>
                                            <th>Prix</th>
                                            <th>ROI (%)</th>
                                            <th>Durée (mois)</th>
                                            <th>Ordre</th>
                                            <th>Statut</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse($category->products as $product)
                                            <tr>
                                                <td>{{ $product->name }}</td>
                                                <td>{{ number_format($product->price, 0, ',', ' ') }} XOF</td>
                                                <td>{{ $product->roi_percentage ?? '-' }}</td>
                                                <td>{{ $product->duration_months ?? '-' }}</td>
                                                <td>{{ $product->order ?? 0 }}</td>
                                                <td>
                                                    <span class="badge badge-{{ $product->is_active ? 'success' : 'secondary' }}">
                                                        {{ $product->is_active ? 'Actif' : 'Inactif' }}
                                                    </span>
                                                </td>
                                                <td>
                                                    <a href="{{ route('admin.investment-products.edit', $product->id) }}" class="btn btn-sm btn-outline-primary">Modifier</a>
                                                    <form action="{{ route('admin.investment-products.destroy', $product->id) }}" method="POST" class="d-inline">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button class="btn btn-sm btn-outline-danger" onclick="return confirm('Supprimer ce produit ?')">Supprimer</button>
                                                    </form>
                                                </td>
                                            </tr>
                                        @empty
                                            <tr>
                                                <td colspan="7" class="text-muted text-center">Aucun produit dans cette catégorie</td>
                                            </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <hr>
                    @empty
                        <p class="text-muted">Aucune catégorie d'investissement.</p>
                    @endforelse
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
