@extends('layouts.app') @section('title', session('locale', 'en') === 'fr' ? 'Tableau de bord' : 'My Dashboard') @section('page-title', session('locale', 'en') === 'fr' ? 'Mes produits' : 'My Products') @section('content') @php $lang = session('locale', 'en'); $t = [ 'en' => [ 'dashboard' => 'Dashboard', 'total' => 'Total Products', 'available' => 'Active', 'sold' => 'Sold', 'expired' => 'Expired', 'value' => 'Total Value', 'views' => 'Views', 'seller' => 'SELLER PANEL', 'add_title' => 'Create a New Listing', 'add_text' => 'Publish a product or service and reach more customers.', 'add_btn' => '+ Add Product', 'my_products' => 'My Products', 'manage' => 'Manage, renew and track all your listings.', 'no_category' => 'No category', 'size' => 'Size', 'no_description' => 'No description added.', 'edit' => 'Edit', 'delete' => 'Delete', 'confirm' => 'Are you sure you want to delete this product?', 'empty' => 'No products yet', 'empty_text' => 'Create your first listing to get started.', 'days_left' => 'days left', 'expired_label' => 'Expired', 'renew' => 'Renew Listing', 'view_listing' => 'View', 'status' => 'Status', 'active_until' => 'Active until', 'not_available' => 'Not available', 'email_stats' => 'Email My Statistics', 'email_stats_hint' => 'Receive a professional performance report by email.', 'performance' => 'Performance Overview', 'top_listings' => 'Top Listings by Views', 'total_views' => 'Total Views', 'average_views' => 'Average Views', 'active_rate' => 'Active Rate', 'seller_report' => 'Seller Report', ], 'fr' => [ 'dashboard' => 'Tableau de bord', 'total' => 'Total des produits', 'available' => 'Actifs', 'sold' => 'Vendus', 'expired' => 'Expirés', 'value' => 'Valeur totale', 'views' => 'Vues', 'seller' => 'PANNEAU VENDEUR', 'add_title' => 'Créer une nouvelle annonce', 'add_text' => 'Publiez un produit ou un service et rejoignez plus de clients.', 'add_btn' => '+ Ajouter un produit', 'my_products' => 'Mes produits', 'manage' => 'Gérez, renouvelez et suivez toutes vos annonces.', 'no_category' => 'Aucune catégorie', 'size' => 'Taille', 'no_description' => 'Aucune description ajoutée.', 'edit' => 'Modifier', 'delete' => 'Supprimer', 'confirm' => 'Voulez-vous vraiment supprimer ce produit ?', 'empty' => 'Aucun produit', 'empty_text' => 'Créez votre première annonce pour commencer.', 'days_left' => 'jours restants', 'expired_label' => 'Expirée', 'renew' => 'Renouveler l’annonce', 'view_listing' => 'Voir', 'status' => 'Statut', 'active_until' => 'Active jusqu’au', 'not_available' => 'Non disponible', 'email_stats' => 'Envoyer mes statistiques par courriel', 'email_stats_hint' => 'Recevez un rapport professionnel de performance par courriel.', 'performance' => 'Aperçu des performances', 'top_listings' => 'Meilleures annonces par vues', 'total_views' => 'Vues totales', 'average_views' => 'Vues moyennes', 'active_rate' => 'Taux actif', 'seller_report' => 'Rapport vendeur', ], ]; $tr = $t[$lang] ?? $t['en']; $productCollection = collect($products ?? []); $expiredProductsCount = $productCollection->filter(function ($product) { return !$product->is_active || !$product->expires_at || now()->greaterThanOrEqualTo($product->expires_at); })->count(); $soldProductsCount = $productCollection->filter(function ($product) { return strtolower($product->status ?? 'available') === 'sold'; })->count(); $activeProductsCount = $productCollection->filter(function ($product) { $expiresAt = $product->expires_at ? \Carbon\Carbon::parse($product->expires_at) : null; return $product->is_active && $expiresAt && now()->lessThan($expiresAt) && strtolower($product->status ?? 'available') !== 'sold'; })->count(); $totalViewsCount = (int) $productCollection->sum('views'); $averageViewsCount = $productCollection->count() ? round($totalViewsCount / max(1, $productCollection->count())) : 0; $activeRate = $productCollection->count() ? round(($activeProductsCount / max(1, $productCollection->count())) * 100) : 0; $maxViews = max(1, (int) $productCollection->max('views')); $topProducts = $productCollection->sortByDesc(fn ($product) => (int) ($product->views ?? 0))->take(5); @endphp
@if(session('success'))
{{ session('success') }}
@endif
{{ $tr['seller'] }}

{{ $tr['dashboard'] }}

{{ $tr['manage'] }}

{{ $tr['add_btn'] }} @if(\Illuminate\Support\Facades\Route::has('dashboard.email-stats'))
@csrf
@else @endif
📦

{{ $tr['total'] }}

{{ $totalProducts ?? $productCollection->count() }}

✓

{{ $tr['available'] }}

{{ $availableProducts ?? $activeProductsCount }}

⏳

{{ $tr['expired'] }}

{{ $expiredProductsCount }}

💰

{{ $tr['value'] }}

${{ number_format($totalValue ?? 0, 2) }}

👁

{{ $tr['total_views'] }}

{{ number_format($totalViewsCount) }}

📊

{{ $tr['average_views'] }}

{{ number_format($averageViewsCount) }}

{{ $tr['seller_report'] }}

{{ $tr['performance'] }}

{{ $tr['email_stats_hint'] }}

@if(\Illuminate\Support\Facades\Route::has('dashboard.email-stats'))
@csrf
@else @endif
{{ $activeRate }}%

{{ $tr['active_rate'] }}

{{ $activeProductsCount }} {{ $tr['available'] }} · {{ $expiredProductsCount }} {{ $tr['expired'] }} · {{ $soldProductsCount }} {{ $tr['sold'] }}

{{ $tr['top_listings'] }}

{{ number_format($totalViewsCount) }} {{ $tr['views'] }}
@forelse($topProducts as $topProduct) @php $viewCount = (int) ($topProduct->views ?? 0); $barWidth = max(4, round(($viewCount / $maxViews) * 100)); @endphp
{{ \Illuminate\Support\Str::limit($topProduct->title, 32) }}{{ number_format($viewCount) }} {{ $tr['views'] }}
@empty
{{ $tr['empty_text'] }}
@endforelse
{{ $tr['seller'] }}

{{ $tr['my_products'] }}

{{ $tr['manage'] }}

{{ $tr['add_btn'] }}
@forelse($products as $product) @php $images = is_array($product->images) ? $product->images : json_decode($product->images ?? '[]', true); $images = is_array($images) ? $images : []; $firstImage = $images[0] ?? null; $imageUrl = null; if ($firstImage) { $normalizedImage = str_replace('\\', '/', trim($firstImage)); if (\Illuminate\Support\Str::startsWith($normalizedImage, ['http://', 'https://', '//'])) { $imageUrl = $normalizedImage; } else { $imageUrl = asset('storage/' . ltrim($normalizedImage, '/')); } } $expiresAt = $product->expires_at ? \Carbon\Carbon::parse($product->expires_at) : null; $daysLeft = $expiresAt ? (int) ceil(now()->diffInHours($expiresAt, false) / 24) : 0; $isExpired = !$product->is_active || !$expiresAt || now()->greaterThanOrEqualTo($expiresAt); $displayPrice = $product->discount_price ?: $product->price; $cleanDescription = trim( preg_replace( '/\s+/', ' ', strip_tags($product->description ?? '') ) ); @endphp
@if($imageUrl) {{ $product->title }} @else
📷
@endif
@if($isExpired) ⛔ {{ $tr['expired_label'] }} @else ⏳ {{ max(0, $daysLeft) }} {{ $tr['days_left'] }} @endif @if($product->status === 'sold') {{ $tr['sold'] }} @elseif($isExpired) {{ $tr['expired_label'] }} @else {{ $tr['available'] }} @endif
{{ $product->category ?: $tr['no_category'] }}

{{ $product->title }}

${{ number_format($displayPrice, 2) }}
👁 {{ number_format($product->views ?? 0) }} {{ $tr['views'] }} @if($product->size) 📏 {{ $tr['size'] }}: {{ $product->size }} @endif

{{ $cleanDescription ? \Illuminate\Support\Str::limit($cleanDescription, 115) : $tr['no_description'] }}

{{ $tr['active_until'] }} {{ $expiresAt ? \Carbon\Carbon::parse($expiresAt)->format('M d, Y') : $tr['not_available'] }}
@if($isExpired) 💳 {{ $tr['renew'] }} @else ✏️ {{ $tr['edit'] }} @endif @if(\Illuminate\Support\Facades\Route::has('product.show')) 👁 {{ $tr['view_listing'] }} @endif
@csrf @method('DELETE')
@empty
📦

{{ $tr['empty'] }}

{{ $tr['empty_text'] }}

{{ $tr['add_btn'] }}
@endforelse
@endsection