<?php
/**
 * Script de test complet du dashboard Analytics
 */

require_once __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();

use App\Http\Controllers\Admin\AnalyticsController;
use App\Services\AiService;
use Illuminate\Http\Request;

echo "=== TEST COMPLET ANALYTICS CONTROLLER ===\n\n";

try {
    $aiService = app(AiService::class);
    $controller = new AnalyticsController($aiService);

    // Test 1: Onglet Overview
    echo "1. Testing Overview Tab...\n";
    $request = new Request(['tab' => 'overview']);
    $response = $controller->index($request);
    echo "   ✓ Overview OK\n\n";

    // Test 2: Onglet Members
    echo "2. Testing Members Tab...\n";
    $request = new Request(['tab' => 'members']);
    $response = $controller->index($request);
    echo "   ✓ Members OK\n\n";

    // Test 3: Onglet Products
    echo "3. Testing Products Tab...\n";
    $request = new Request(['tab' => 'products']);
    $response = $controller->index($request);
    echo "   ✓ Products OK\n\n";

    // Test 4: Onglet AMM
    echo "4. Testing AMM Tab...\n";
    $request = new Request(['tab' => 'amm']);
    $response = $controller->index($request);
    echo "   ✓ AMM OK\n\n";

    // Test 5: Onglet Network
    echo "5. Testing Network Tab...\n";
    $request = new Request(['tab' => 'network']);
    $response = $controller->index($request);
    echo "   ✓ Network OK\n\n";

    // Test 6: Onglet AI
    echo "6. Testing AI & Insights Tab...\n";
    $request = new Request(['tab' => 'ai']);
    $response = $controller->index($request);
    echo "   ✓ AI & Insights OK\n\n";

    echo "=== TOUS LES TESTS PASSÉS ===\n";
    echo "\nLe dashboard Analytics est prêt !\n";
    echo "URL: /admin/analytics\n";
    echo "\nOnglets disponibles:\n";
    echo "  - Vue d'ensemble: /admin/analytics?tab=overview\n";
    echo "  - Membres: /admin/analytics?tab=members\n";
    echo "  - Produits: /admin/analytics?tab=products\n";
    echo "  - Suivi AMM: /admin/analytics?tab=amm\n";
    echo "  - Réseau MLM: /admin/analytics?tab=network\n";
    echo "  - IA & Insights: /admin/analytics?tab=ai\n";

} catch (Exception $e) {
    echo "ERREUR: " . $e->getMessage() . "\n";
    echo "File: " . $e->getFile() . " Line: " . $e->getLine() . "\n";
    echo "\nTrace:\n" . $e->getTraceAsString() . "\n";
}
