<div>
    <div class="container mx-auto flex flex-col lg:flex-row gap-6">

        <!--[if BLOCK]><![endif]--><?php if(settings('merchant_status') == \App\Models\Merchant::STATUS_ACTIVE): ?>
            <div class="w-full lg:w-full flex-1">
                <!-- Stats -->
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
                    <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $stats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if (isset($component)) { $__componentOriginal37182d56429d4ad269914247bc70813e = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal37182d56429d4ad269914247bc70813e = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.stats-card','data' => ['title' => $stat['title'],'count' => $stat['count'],'subtitle' => $stat['subtitle'],'color' => $stat['color'],'icon' => $stat['icon'],'link' => $stat['link']]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.stats-card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($stat['title']),'count' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($stat['count']),'subtitle' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($stat['subtitle']),'color' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($stat['color']),'icon' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($stat['icon']),'link' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($stat['link'])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal37182d56429d4ad269914247bc70813e)): ?>
<?php $attributes = $__attributesOriginal37182d56429d4ad269914247bc70813e; ?>
<?php unset($__attributesOriginal37182d56429d4ad269914247bc70813e); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal37182d56429d4ad269914247bc70813e)): ?>
<?php $component = $__componentOriginal37182d56429d4ad269914247bc70813e; ?>
<?php unset($__componentOriginal37182d56429d4ad269914247bc70813e); ?>
<?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                </div>

                <!-- Charts -->
                <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8" x-data="pharmacyDashboard()" x-init="init()">

                    <?php if (isset($component)) { $__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.card','data' => ['title' => 'Flux financier','subtitle' => 'Ventes et dépenses des 7 derniers jours']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Flux financier','subtitle' => 'Ventes et dépenses des 7 derniers jours']); ?>
                        <div class="h-80">
                            <canvas id="weeklyFinancialChart"></canvas>
                        </div>
                     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f)): ?>
<?php $attributes = $__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f; ?>
<?php unset($__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f)): ?>
<?php $component = $__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f; ?>
<?php unset($__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f); ?>
<?php endif; ?>

                    <?php if (isset($component)) { $__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.card','data' => ['title' => 'Méthodes de paiement','subtitle' => 'Répartition des paiements reçus']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Méthodes de paiement','subtitle' => 'Répartition des paiements reçus']); ?>
                        <div class="h-80">
                            <canvas id="paymentMethodsChart"></canvas>
                        </div>
                     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f)): ?>
<?php $attributes = $__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f; ?>
<?php unset($__attributesOriginalc6553a56e7fe7b7a7297dae4cf77349f); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f)): ?>
<?php $component = $__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f; ?>
<?php unset($__componentOriginalc6553a56e7fe7b7a7297dae4cf77349f); ?>
<?php endif; ?>
                </div>

                <!-- Recent Sales Table -->
                <div class="bg-white border border-gray-300 rounded overflow-hidden shadow-sm mb-8">
                    <div class="p-4 border-b">
                        <h4 class="font-semibold text-gray-800">Ventes récentes</h4>
                    </div>
                    <div class="overflow-x-auto">
                        <!--[if BLOCK]><![endif]--><?php if($recentSales->count() > 0): ?>
                            <table class="min-w-full text-sm">
                                <thead class="bg-gray-100">
                                    <tr>
                                        <th class="p-3 text-left font-medium text-gray-700 w-10">#</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Numéro de vente</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Montant total</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Méthode de paiement</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Statut</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Date de création</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $recentSales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sale): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr class="border-t hover:bg-gray-50">
                                            <td class="px-3 py-2 font-medium"><?php echo e($loop->iteration); ?>.</td>
                                            <td class="px-3 py-2">
                                                <?php if (isset($component)) { $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.link','data' => ['size' => 'normal','href' => ''.e(route('sales.show', $sale)).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['size' => 'normal','href' => ''.e(route('sales.show', $sale)).'']); ?>
                                                    <?php echo e($sale->sale_number ?? 'N/A'); ?>

                                                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $attributes = $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $component = $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
                                            </td>
                                            <td class="px-3 py-2 text-gray-900 font-medium">
                                                <?php echo e(number_format($sale->total_amount, 0, ',', ' ')); ?>

                                                <?php echo \App\Models\Setting::DEFAULT_CURRENCY; ?>

                                            </td>
                                            <td class="px-3 py-2 text-gray-600">
                                                <?php echo $sale->getPaymentMethodBadge(); ?>

                                            </td>
                                            <td class="px-3 py-2">
                                                <?php echo $sale->getStatusBadge(); ?>

                                            </td>
                                            <td class="px-3 py-2 text-gray-600">
                                                <?php echo e($sale->created_at->format('d/m/Y H:i')); ?>

                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                                </tbody>
                            </table>
                        <?php else: ?>
                            <div class="text-center py-12">
                                <div class="text-gray-500">
                                    <i class="ph ph-receipt text-4xl mb-4"></i>
                                    <p class="text-lg font-medium">Aucune vente trouvée</p>
                                </div>
                            </div>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!--[if BLOCK]><![endif]--><?php if($recentSales->count() > 0): ?>
                        <div class="p-4 border-t bg-gray-50">
                            <div class="flex justify-between items-center">
                                <p class="text-sm text-gray-600">
                                    Affichage des <?php echo e($recentSales->count()); ?> ventes les plus récentes
                                </p>
                                <?php if (isset($component)) { $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.link','data' => ['href' => ''.e(route('sales.index')).'','size' => 'sm','variant' => 'primary']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => ''.e(route('sales.index')).'','size' => 'sm','variant' => 'primary']); ?>
                                    <i class="ph ph-list mr-2"></i>
                                    Voir toutes les ventes
                                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $attributes = $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $component = $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                </div>

                <!-- Top Products Table -->
                <div class="bg-white border border-gray-300 rounded overflow-hidden shadow mb-8">
                    <div class="p-4 border-b">
                        <h4 class="font-semibold text-gray-800">Liste des produits</h4>
                    </div>
                    <div class="overflow-x-auto">
                        <!--[if BLOCK]><![endif]--><?php if($topProducts->count() > 0): ?>
                            <table class="min-w-full text-sm">
                                <thead class="bg-gray-100">
                                    <tr>
                                        <th class="p-3 text-left font-medium text-gray-700 w-10">#</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Produit</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Catégorie</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Prix de vente</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Stock</th>
                                        <th class="p-3 text-left font-medium text-gray-700">Statut</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $topProducts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr class="border-t hover:bg-gray-50">
                                            <td class="px-3 py-2">
                                                <?php echo e($loop->iteration); ?>.
                                            </td>
                                            <td class="px-3 py-2">
                                                <?php if (isset($component)) { $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.link','data' => ['size' => '','href' => ''.e(route('products.show', $product)).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['size' => '','href' => ''.e(route('products.show', $product)).'']); ?><?php echo e($product->name ?? '—'); ?> <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $attributes = $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $component = $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
                                            </td>

                                            <td class="px-3 py-2 text-gray-600">
                                                <?php echo e($product->category?->name ?? '—'); ?>

                                            </td>

                                            <td class="px-3 py-2 text-gray-600">
                                                <?php echo e($product->selling_price ? number_format($product->selling_price, 2) . ' CDF' : '—'); ?>

                                            </td>

                                            <td class="px-3 py-2 text-gray-600">
                                                <?php echo $product->getStockQuantityBadge(); ?>

                                            </td>

                                            <td class="px-3 py-2">
                                                <?php echo $product->getStatusBadge(); ?>

                                            </td>

                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                                </tbody>
                            </table>
                        <?php else: ?>
                            <div class="text-center py-12">
                                <div class="text-gray-500">
                                    <i class="ph ph-package text-4xl mb-4"></i>
                                    <p class="text-lg font-medium">Aucun produit trouvé</p>
                                </div>
                            </div>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!--[if BLOCK]><![endif]--><?php if($topProducts->count() > 0): ?>
                        <div class="p-4 border-t bg-gray-50">
                            <div class="flex justify-between items-center">
                                <p class="text-sm text-gray-600">
                                    Affichage des <?php echo e($topProducts->count()); ?> produits avec le plus de stock
                                </p>
                                <?php if (isset($component)) { $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.link','data' => ['href' => ''.e(route('products.index')).'','size' => 'sm','variant' => 'primary']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => ''.e(route('products.index')).'','size' => 'sm','variant' => 'primary']); ?>
                                    <i class="ph ph-list mr-2"></i>
                                    Voir tous les produits
                                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $attributes = $__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__attributesOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a)): ?>
<?php $component = $__componentOriginalb8a61dc3cc5465365f8da62a3465be9a; ?>
<?php unset($__componentOriginalb8a61dc3cc5465365f8da62a3465be9a); ?>
<?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                </div>

                <!-- Recent Prescriptions Table -->
                <?php
$__split = function ($name, $params = []) {
    return [$name, $params];
};
[$__name, $__params] = $__split('dashboard.latest-prescription-table', []);

$__html = app('livewire')->mount($__name, $__params, 'lw-1565826842-0', $__slots ?? [], get_defined_vars());

echo $__html;

unset($__html);
unset($__name);
unset($__params);
unset($__split);
if (isset($__slots)) unset($__slots);
?>
            </div>
        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->


        <?php if(settings('merchant_status') == \App\Models\Merchant::STATUS_DRAFT): ?>
            <div class="w-full flex-1">
                <div class="w-full rounded-xl border border-blue-200 bg-gradient-to-br from-blue-50 to-white p-6">
                    <div class="grid grid-cols-1 lg:grid-cols-2 items-stretch gap-6">
                        <!-- Left: Message & CTA -->
                        <div class="flex-1 flex flex-col justify-between h-full">
                            <div class="flex items-start gap-3">
                                <div class="flex-shrink-0">
                                    <span class="inline-flex h-10 w-10 items-center justify-center rounded-full bg-blue-100 text-blue-700">
                                        <i class="ph ph-info text-xl"></i>
                                    </span>
                                </div>
                                <div class="flex-1">
                                    <h3 class="text-base font-semibold text-blue-900">
                                        Établissement en attente d'activation
                                    </h3>
                                    <p class="mt-2 text-sm text-blue-800/90">
                                        Activez votre établissement pour débloquer toutes les fonctionnalités professionnelles
                                        de la plateforme.
                                    </p>
                                    <ul class="mt-4 text-sm text-blue-900 space-y-2">
                                        <li class="flex items-start gap-2"><i class="ph ph-check-circle text-blue-700 mt-0.5"></i> <span>Complétez les informations de votre établissement</span></li>
                                        <li class="flex items-start gap-2"><i class="ph ph-wifi-high text-blue-700 mt-0.5"></i> <span>Vérifiez votre connexion internet</span></li>
                                    </ul>

                                    <?php
                                        $settingsData = settings();
                                        $hasInfo = ! empty($settingsData['merchant_name'] ?? null) && ! empty($settingsData['merchant_code'] ?? null);
                                        $hasSubscription = session('active_subscription_id') ? true : false;
                                        $stepsTotal = 3;
                                        $stepsDone = ($hasInfo ? 1 : 0) + ($hasSubscription ? 1 : 0);
                                        $progress = intval(($stepsDone / $stepsTotal) * 100);
                                    ?>

                                    <div class="mt-5">
                                        <div class="flex items-center justify-between mb-2">
                                            <span class="text-xs font-medium text-blue-900">Progression de l'activation</span>
                                            <span class="text-xs text-blue-900/70"><?php echo e($stepsDone); ?> / <?php echo e($stepsTotal); ?></span>
                                        </div>
                                        <div class="w-full h-2 rounded bg-blue-100 overflow-hidden">
                                            <div class="h-full bg-blue-600" style="width: <?php echo e($progress); ?>%"></div>
                                        </div>
                                        <div class="mt-3 space-y-2 text-sm">
                                            <div class="flex items-center gap-2">
                                                <i class="ph <?php echo e($hasInfo ? 'ph-check-circle text-emerald-600' : 'ph-circle text-gray-400'); ?>"></i>
                                                <span class="text-blue-900">Informations d'établissement</span>
                                                <!--[if BLOCK]><![endif]--><?php if($hasInfo): ?>
                                                    <span class="ml-auto text-xs text-emerald-700 bg-emerald-100 px-2 py-0.5 rounded">OK</span>
                                                <?php else: ?>
                                                    <a href="<?php echo e(route('merchant.edit')); ?>" class="ml-auto text-xs text-blue-700 hover:underline">Compléter</a>
                                                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                            </div>
                                            <div class="flex items-center gap-2">
                                                <i class="ph <?php echo e($hasSubscription ? 'ph-check-circle text-emerald-600' : 'ph-lock-simple text-gray-400'); ?>"></i>
                                                <span class="text-blue-900">Abonnement actif</span>
                                                <!--[if BLOCK]><![endif]--><?php if($hasSubscription): ?>
                                                    <span class="ml-auto text-xs text-emerald-700 bg-emerald-100 px-2 py-0.5 rounded">Actif</span>
                                                <?php else: ?>
                                                    <a href="<?php echo e(url('subscriptions')); ?>" class="ml-auto text-xs text-blue-700 hover:underline">Activer</a>
                                                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                            </div>
                                            <div class="flex items-center gap-2">
                                                <i class="ph ph-wifi-high text-blue-600"></i>
                                                <span class="text-blue-900">Connexion internet</span>
                                                <span class="ml-auto text-xs text-blue-700 bg-blue-100 px-2 py-0.5 rounded">À vérifier</span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="mt-5">
                                        <h4 class="text-xs font-semibold text-blue-900 uppercase tracking-wide">Pourquoi activer ?</h4>
                                        <ul class="mt-2 text-sm text-blue-900/90 space-y-1">
                                            <li class="flex items-start gap-2"><i class="ph ph-lightning text-amber-500 mt-0.5"></i> Accès complet aux modules métiers</li>
                                            <li class="flex items-start gap-2"><i class="ph ph-cloud-check text-blue-600 mt-0.5"></i> Sauvegarde & synchronisation sécurisées</li>
                                            <li class="flex items-start gap-2"><i class="ph ph-chart-line-up text-emerald-600 mt-0.5"></i> Rapports et analyses détaillés</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>

                            <div class="mt-6">
                                <?php if (isset($component)) { $__componentOriginal079d60308294c5043ebbe594686deab0 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal079d60308294c5043ebbe594686deab0 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.basics.button-link','data' => ['href' => ''.e(route('merchant.edit')).'','class' => 'w-full','variant' => 'primary','icon' => '<i class="ph ph-play-circle"></i>']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('basics.button-link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => ''.e(route('merchant.edit')).'','class' => 'w-full','variant' => 'primary','icon' => '<i class="ph ph-play-circle"></i>']); ?>
                                    Activer l'établissement
                                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal079d60308294c5043ebbe594686deab0)): ?>
<?php $attributes = $__attributesOriginal079d60308294c5043ebbe594686deab0; ?>
<?php unset($__attributesOriginal079d60308294c5043ebbe594686deab0); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal079d60308294c5043ebbe594686deab0)): ?>
<?php $component = $__componentOriginal079d60308294c5043ebbe594686deab0; ?>
<?php unset($__componentOriginal079d60308294c5043ebbe594686deab0); ?>
<?php endif; ?>
                            </div>
                        </div>

                        <!-- Right: Locked features preview -->
                        <div class="flex-1 bg-white/60 backdrop-blur rounded-lg border border-blue-100 p-5 h-full">
                            <h4 class="text-sm font-semibold text-gray-800 mb-4">Fonctionnalités débloquées après activation</h4>
                            <div class="flex flex-col gap-3">
                                <?php
                                    $features = [
                                        ['name' => 'Ventes', 'icon' => 'ph ph-shopping-cart', 'desc' => "Créer des ventes, remises, retours et reçus."],
                                        ['name' => 'Clients', 'icon' => 'ph ph-users', 'desc' => "Gérer la clientèle et l'historique des achats."],
                                        ['name' => 'Inventaire', 'icon' => 'ph ph-package', 'desc' => "Suivre les stocks, réceptions et ajustements."],
                                        ['name' => 'Prescriptions', 'icon' => 'ph ph-prescription', 'desc' => "Recevoir, traiter et archiver les ordonnances."],
                                        ['name' => 'Fournisseurs', 'icon' => 'ph ph-truck', 'desc' => "Gérer les fournisseurs et les bons de commande."],
                                        ['name' => 'Rapports', 'icon' => 'ph ph-chart-line-up', 'desc' => "Analyser les performances et indicateurs clés."],
                                    ];
                                ?>

                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $features; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $f): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div class="relative rounded-md border border-gray-200 bg-white p-4 flex items-start gap-3">
                                        <span class="inline-flex h-9 w-9 items-center justify-center rounded-md bg-gray-100 text-gray-700 shrink-0">
                                            <i class="<?php echo e($f['icon']); ?> text-lg"></i>
                                        </span>
                                        <div class="flex-1">
                                            <div class="flex items-center justify-between">
                                                <p class="text-sm font-medium text-gray-800"><?php echo e($f['name']); ?></p>
                                                <i class="ph ph-lock-simple text-gray-400"></i>
                                            </div>
                                            <p class="text-xs text-gray-500 mt-1"><?php echo e($f['desc']); ?></p>
                                        </div>
                                    </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </div>

                            <p class="mt-4 text-xs text-gray-500">Astuce: activez votre établissement pour accéder immédiatement à ces modules.</p>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->


        <?php if(settings('merchant_status') == \App\Models\Merchant::STATUS_SUSPENDED): ?>
            <div class="w-full lg:w-full flex-1">
                <div class="bg-orange-50 border border-orange-200 rounded-lg p-6">
                    <div class="flex items-start">
                        <div class="flex-shrink-0">
                            <i class="ph ph-warning text-orange-600 text-xl"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-sm font-medium text-orange-800 mb-2">
                                Établissement suspendu
                            </h3>
                            <div class="text-sm text-orange-700 space-y-1">
                                <p>Votre établissement a été temporairement suspendu. Pour le réactiver
                                    :</p>
                                <ul class="list-disc list-inside mt-2 space-y-1">
                                    <li>Complétez les informations manquantes</li>
                                    <li>Vérifiez que votre connexion internet est active</li>
                                    <li>Contactez le support si nécessaire</li>
                                </ul>
                                <p class="mt-3 font-medium">La réactivation peut être effectuée à tout
                                    moment.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

    </div>

    <?php $__env->startPush('scripts'); ?>
        <!--[if BLOCK]><![endif]--><?php if($isMerchantActive): ?>
            <script src="<?php echo e(asset('plugins/chartjs/chart.min.js')); ?>"></script>
            <script>
                // Ensure Chart.js is available even when navigating with wire:navigate
                const chartJsUrl = "<?php echo e(asset('plugins/chartjs/chart.min.js')); ?>";

                function loadScriptOnce(url) {
                    return new Promise((resolve, reject) => {
                        if (document.querySelector(`script[src="${url}"]`)) {
                            // If already in DOM but Chart not ready yet, wait for load event once
                            if (window.Chart) {
                                return resolve();
                            }
                        }

                        if (window.__chartJsLoadingPromise) {
                            window.__chartJsLoadingPromise.then(resolve).catch(reject);
                            return;
                        }

                        const script = document.createElement('script');
                        script.src = url;
                        script.async = true;
                        window.__chartJsLoadingPromise = new Promise((res, rej) => {
                            script.onload = () => res();
                            script.onerror = (e) => rej(e);
                        });
                        document.head.appendChild(script);
                        window.__chartJsLoadingPromise.then(resolve).catch(reject);
                    });
                }

                async function ensureChartJs() {
                    if (typeof window.Chart === 'undefined') {
                        await loadScriptOnce(chartJsUrl);
                    }
                }

                function pharmacyDashboard() {
                    return {
                        async init() {
                            // Make sure Chart.js is loaded (wire:navigate may skip script execution)
                            try {
                                await ensureChartJs();
                            } catch (e) {
                                console.error('Failed to load Chart.js:', e);
                                return;
                            }
                            // Simple currency formatter for JavaScript
                            function formatCurrencyJS(amount) {
                                if (amount === null || amount === undefined) {
                                    return '0,00 CDF';
                                }
                                return new Intl.NumberFormat('fr-FR', {
                                    style: 'currency',
                                    currency: 'CDF',
                                    minimumFractionDigits: 2
                                }).format(amount);
                            }

                            try {
                                const weeklyFinancialCanvas = document.getElementById('weeklyFinancialChart');
                                if (!weeklyFinancialCanvas) throw new Error('weeklyFinancialChart canvas not found');
                                const weeklyFinancialCtx = weeklyFinancialCanvas.getContext('2d');
                                // Destroy existing instance if re-initializing after wire:navigate
                                if (window.Chart && typeof Chart.getChart === 'function') {
                                    const existingWeekly = Chart.getChart(weeklyFinancialCanvas);
                                    if (existingWeekly) existingWeekly.destroy();
                                }
                                console.log('Weekly financial chart canvas found:', weeklyFinancialCtx);
                                new Chart(weeklyFinancialCtx, {
                                    type: 'bar',
                                    data: {
                                        labels: <?php echo json_encode($weeklyFinancialChart['labels'], 15, 512) ?>,
                                        datasets: [{
                                            label: 'Ventes',
                                            data: <?php echo json_encode($weeklyFinancialChart['sales_data'], 15, 512) ?>,
                                            backgroundColor: 'rgba(16, 185, 129, 0.8)',
                                            borderColor: '#10B981',
                                            borderWidth: 2,
                                            borderRadius: 4,
                                            borderSkipped: false,
                                        }, {
                                            label: 'Dépenses',
                                            data: <?php echo json_encode($weeklyFinancialChart['expenses_data'], 15, 512) ?>,
                                            backgroundColor: 'rgba(239, 68, 68, 0.8)',
                                            borderColor: '#EF4444',
                                            borderWidth: 2,
                                            borderRadius: 4,
                                            borderSkipped: false,
                                        }]
                                    },
                                    options: {
                                        responsive: true,
                                        maintainAspectRatio: false,
                                        plugins: {
                                            legend: {
                                                display: true,
                                                position: 'top',
                                                labels: {
                                                    usePointStyle: true,
                                                    padding: 20
                                                }
                                            },
                                            tooltip: {
                                                callbacks: {
                                                    label: function(context) {
                                                        return context.dataset.label + ': ' + formatCurrencyJS(context
                                                            .parsed.y);
                                                    }
                                                }
                                            }
                                        },
                                        scales: {
                                            y: {
                                                beginAtZero: true,
                                                ticks: {
                                                    callback: function(value) {
                                                        return formatCurrencyJS(value);
                                                    }
                                                }
                                            },
                                            x: {
                                                display: true,
                                                title: {
                                                    display: true,
                                                    text: 'Derniers 7 jours'
                                                }
                                            }
                                        }
                                    }
                                });
                            } catch (error) {
                                console.error('Error creating weekly financial chart:', error);
                            }

                            try {
                                const paymentMethodsCanvas = document.getElementById('paymentMethodsChart');
                                if (!paymentMethodsCanvas) throw new Error('paymentMethodsChart canvas not found');
                                const paymentMethodsCtx = paymentMethodsCanvas.getContext('2d');
                                // Destroy existing instance if re-initializing after wire:navigate
                                if (window.Chart && typeof Chart.getChart === 'function') {
                                    const existingPayment = Chart.getChart(paymentMethodsCanvas);
                                    if (existingPayment) existingPayment.destroy();
                                }
                                console.log('Payment methods chart canvas found:', paymentMethodsCtx);
                                new Chart(paymentMethodsCtx, {
                                    type: 'doughnut',
                                    data: {
                                        labels: <?php echo json_encode($paymentMethodsChart['labels'], 15, 512) ?>,
                                        datasets: [{
                                            data: <?php echo json_encode($paymentMethodsChart['data'], 15, 512) ?>,
                                            backgroundColor: [
                                                '#10B981', // Cash - Green
                                                '#F59E0B', // Debt - Orange  
                                                '#8B5CF6', // Mobile Money - Purple
                                                '#3B82F6', // Card - Blue
                                                '#EF4444', // Transfer - Red
                                                '#06B6D4', // Other - Cyan
                                            ],
                                            borderWidth: 2,
                                            borderColor: '#ffffff'
                                        }]
                                    },
                                    options: {
                                        responsive: true,
                                        maintainAspectRatio: false,
                                        plugins: {
                                            legend: {
                                                position: 'bottom',
                                                labels: {
                                                    fontSize: 12,
                                                    padding: 10,
                                                    usePointStyle: true
                                                }
                                            },
                                            tooltip: {
                                                callbacks: {
                                                    label: function(context) {
                                                        const total = context.dataset.data.reduce((a, b) => a + b, 0);
                                                        const percentage = ((context.parsed / total) * 100).toFixed(1);
                                                        return context.label + ': ' + formatCurrencyJS(context.parsed) +
                                                            ' (' + percentage + '%)';
                                                    }
                                                }
                                            }
                                        }
                                    }
                                });
                            } catch (error) {
                                console.error('Error creating payment methods chart:', error);
                            }
                        }
                    }
                }
                document.addEventListener('alpine:init', () => {
                    Alpine.data('pharmacyDashboard', pharmacyDashboard);
                });

                // Alternative initialization if Alpine.js doesn't work
                document.addEventListener('DOMContentLoaded', () => {
                    setTimeout(() => {
                        if (typeof pharmacyDashboard !== 'undefined') {
                            try {
                                const dashboard = pharmacyDashboard();
                                if (dashboard && typeof dashboard.init === 'function') {
                                    dashboard.init();
                                }
                            } catch (e) {
                                console.error('Fallback init failed:', e);
                            }
                        }
                    }, 100);
                });

                // Re-initialize charts after Livewire wire:navigate navigations
                document.addEventListener('livewire:navigated', () => {
                    try {
                        if (typeof pharmacyDashboard !== 'undefined') {
                            const hasCharts = document.getElementById('weeklyFinancialChart') || document.getElementById('paymentMethodsChart');
                            if (hasCharts) {
                                const dashboard = pharmacyDashboard();
                                if (dashboard && typeof dashboard.init === 'function') {
                                    dashboard.init();
                                }
                            }
                        }
                    } catch (e) {
                        console.error('Re-initializing charts after navigation failed:', e);
                    }
                });
            </script>
        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
    <?php $__env->stopPush(); ?>
</div>
<?php /**PATH D:\WORK\MAARIFA\ANGO\DESKTOP\V4\ango-desktop\resources\views/livewire/home.blade.php ENDPATH**/ ?>