<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                Live Analytics
            </h2>
            <div class="flex space-x-4">
                <button onclick="location.reload()" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
                    🔄 Refresh
                </button>
                <a href="<?php echo e(route('admin.analytics.index')); ?>" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
                    Back to Analytics
                </a>
            </div>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-8">
            <!-- Auto-refresh notification -->
            <div class="bg-blue-100 border border-blue-400 text-blue-700 px-4 py-3 rounded">
                <p class="text-sm">
                    📡 <strong>Live View:</strong> Showing activity from the last 5 minutes. 
                    Page will auto-refresh every 30 seconds.
                </p>
            </div>

            <!-- Recent Interactions -->
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-semibold text-gray-900">Recent Interactions (Last 5 minutes)</h3>
                        <span class="text-sm text-gray-500"><?php echo e($recentInteractions->count()); ?> interactions</span>
                    </div>
                    
                    <?php if($recentInteractions->count() > 0): ?>
                        <div class="space-y-2">
                            <?php $__currentLoopData = $recentInteractions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $interaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $icons = [
                                        'view' => '👁️',
                                        'click' => '🖱️',
                                        'watchlist_add' => '⭐',
                                        'message' => '💬',
                                        'buy_interest' => '💰'
                                    ];
                                    $colors = [
                                        'view' => 'bg-blue-50 border-blue-200',
                                        'click' => 'bg-green-50 border-green-200',
                                        'watchlist_add' => 'bg-yellow-50 border-yellow-200',
                                        'message' => 'bg-purple-50 border-purple-200',
                                        'buy_interest' => 'bg-red-50 border-red-200'
                                    ];
                                ?>
                                <div class="flex items-center justify-between p-3 border rounded-lg <?php echo e($colors[$interaction->interaction_type] ?? 'bg-gray-50 border-gray-200'); ?>">
                                    <div class="flex items-center space-x-3">
                                        <span class="text-xl"><?php echo e($icons[$interaction->interaction_type] ?? '📈'); ?></span>
                                        <div>
                                            <div class="flex items-center space-x-2">
                                                <span class="font-medium">
                                                    <?php echo e($interaction->user ? $interaction->user->name : 'Anonymous'); ?>

                                                </span>
                                                <span class="text-sm text-gray-600">
                                                    <?php echo e(str_replace('_', ' ', $interaction->interaction_type)); ?>

                                                </span>
                                                <span class="text-sm font-medium">
                                                    <?php echo e(Str::limit($interaction->item->title, 30)); ?>

                                                </span>
                                            </div>
                                            <div class="text-xs text-gray-500">
                                                <?php echo e($interaction->item->category->name); ?> • 
                                                <?php echo e($interaction->created_at->diffForHumans()); ?>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="flex space-x-2">
                                        <?php if($interaction->user): ?>
                                            <a href="<?php echo e(route('admin.analytics.user-details', $interaction->user)); ?>" 
                                               class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded">
                                                User Details
                                            </a>
                                        <?php endif; ?>
                                        <a href="<?php echo e(route('admin.analytics.item-details', $interaction->item)); ?>" 
                                           class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded">
                                            Item Analytics
                                        </a>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center py-8">
                            <span class="text-4xl mb-4 block">😴</span>
                            <h3 class="text-lg font-medium text-gray-900">No recent activity</h3>
                            <p class="text-gray-500">No interactions in the last 5 minutes</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Active Sessions -->
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-semibold text-gray-900">Active Sessions (Last 15 minutes)</h3>
                        <span class="text-sm text-gray-500"><?php echo e($activeSessions->count()); ?> active sessions</span>
                    </div>
                    
                    <?php if($activeSessions->count() > 0): ?>
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                            <?php $__currentLoopData = $activeSessions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $session): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="p-4 border border-gray-200 rounded-lg">
                                    <div class="flex items-center justify-between mb-2">
                                        <span class="font-medium text-gray-900">
                                            <?php if(is_numeric($session->identifier)): ?>
                                                <?php $user = \App\Models\User::find($session->identifier) ?>
                                                <?php echo e($user ? $user->name : 'User #' . $session->identifier); ?>

                                            <?php else: ?>
                                                Anonymous Session
                                            <?php endif; ?>
                                        </span>
                                        <span class="text-xs text-gray-500">
                                            <?php echo e(\Carbon\Carbon::parse($session->last_activity)->diffForHumans()); ?>

                                        </span>
                                    </div>
                                    <div class="flex justify-between items-center">
                                        <span class="text-sm text-gray-600"><?php echo e($session->actions); ?> actions</span>
                                        <?php if(is_numeric($session->identifier)): ?>
                                            <?php $user = \App\Models\User::find($session->identifier) ?>
                                            <?php if($user): ?>
                                                <a href="<?php echo e(route('admin.analytics.user-details', $user)); ?>" 
                                                   class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded">
                                                    View Details
                                                </a>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php else: ?>
                        <div class="text-center py-8">
                            <span class="text-4xl mb-4 block">💤</span>
                            <h3 class="text-lg font-medium text-gray-900">No active sessions</h3>
                            <p class="text-gray-500">No user activity in the last 15 minutes</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <!-- Auto-refresh script -->
    <script>
        // Auto-refresh page every 30 seconds
        setTimeout(function() {
            location.reload();
        }, 30000);

        // Add visual countdown
        let countdown = 30;
        const interval = setInterval(function() {
            countdown--;
            document.title = `Live Analytics (${countdown}s) - <?php echo e(config('app.name')); ?>`;
            if (countdown <= 0) {
                clearInterval(interval);
            }
        }, 1000);
    </script>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH /var/www/html/resources/views/admin/analytics/realtime.blade.php ENDPATH**/ ?>