@extends('layouts.member')

@section('title', 'Pool de Partage')
@section('page-title', 'Pool de Partage')

@section('content')
<div class="row g-4 mb-4">
    <div class="col-md-4 col-sm-6">
        <div class="stat-card modern shadow-sm border-0 rounded-3 text-center">
            <p class="text-muted small mb-1">Total reçu</p>
            <h4 class="text-success fw-700 mb-0">{{ number_format($totalReceived, 0, ',', ' ') }} XOF</h4>
        </div>
    </div>
    <div class="col-md-4 col-sm-6">
        <div class="stat-card modern shadow-sm border-0 rounded-3 text-center">
            <p class="text-muted small mb-1">Participations</p>
            <h4 class="fw-700 mb-0">{{ $distributions->count() }}</h4>
        </div>
    </div>
    <div class="col-md-4 col-sm-12">
        <div class="stat-card modern shadow-sm border-0 rounded-3 text-center">
            @if($isEligible)
                <p class="text-success small mb-1">Éligible ce mois</p>
                <h4 class="text-success fw-700 mb-0">Oui</h4>
            @else
                <p class="text-danger small mb-1">Éligible ce mois</p>
                <h4 class="text-danger fw-700 mb-0">Non</h4>
            @endif
        </div>
    </div>
</div>

<div class="card modern shadow-sm border-0 rounded-3 mb-4">
    <div class="card-header bg-white rounded-top-3">
        <h5 class="mb-0"><i class="bi bi-info-circle me-2"></i>Comment ça fonctionne ?</h5>
    </div>
    <div class="card-body">
        <div class="row g-3">
            <div class="col-md-4 text-center">
                <div class="bg-light rounded-3 p-3 h-100">
                    <i class="bi bi-bag-check fs-1 text-primary mb-2 d-block"></i>
                    <h6>1. Achat Mensuel</h6>
                    <p class="text-muted small mb-0">Atteignez <strong>{{ number_format($minimumPurchase, 0, ',', ' ') }} XOF</strong></p>
                </div>
            </div>
            <div class="col-md-4 text-center">
                <div class="bg-light rounded-3 p-3 h-100">
                    <i class="bi bi-people fs-1 text-success mb-2 d-block"></i>
                    <h6>2. Filleuls Actifs</h6>
                    <p class="text-muted small mb-0">Au moins <strong>{{ $minimumReferrals }}</strong> filleuls actifs</p>
                </div>
            </div>
            <div class="col-md-4 text-center">
                <div class="bg-light rounded-3 p-3 h-100">
                    <i class="bi bi-cash-stack fs-1 text-warning mb-2 d-block"></i>
                    <h6>3. Recevez votre part</h6>
                    <p class="text-muted small mb-0"><strong>{{ $poolPercentage }}%</strong> des ventes redistribuées</p>
                </div>
            </div>
        </div>

        @if(!$isEligible)
        <div class="alert alert-warning mt-3 mb-0">
            <i class="bi bi-exclamation-triangle me-2"></i>
            <strong>Encore quelques étapes :</strong><br>
            @if($monthlyPurchases < $minimumPurchase)
                - Il manque <strong>{{ number_format($minimumPurchase - $monthlyPurchases, 0, ',', ' ') }} XOF</strong> d'achats<br>
            @endif
            @if($activeReferrals < $minimumReferrals)
                - Ajoutez <strong>{{ $minimumReferrals - $activeReferrals }}</strong> filleul(s) actif(s)
            @endif
        </div>
        @endif
    </div>
</div>

<div class="card modern shadow-sm border-0 rounded-3">
    <div class="card-header bg-white rounded-top-3">
        <h5 class="mb-0"><i class="bi bi-clock-history me-2"></i>Mes participations</h5>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Période</th>
                        <th>Reçu</th>
                        <th>Pool total</th>
                        <th>Participants</th>
                        <th>Date</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($distributions as $distribution)
                    <tr>
                        <td><strong>{{ $distribution->period }}</strong></td>
                        <td class="text-success fw-600">{{ number_format($distribution->amount, 0, ',', ' ') }} XOF</td>
                        <td>{{ number_format($distribution->total_pool, 0, ',', ' ') }} XOF</td>
                        <td>{{ $distribution->total_distributors }} personnes</td>
                        <td>{{ $distribution->created_at->format('d/m/Y') }}</td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="5" class="text-center text-muted py-4">
                            <i class="bi bi-inbox fs-2 d-block mb-2"></i>
                            Aucune participation pour le moment
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
