<?php $__env->startSection('title', 'Dashboard - Ojo de Águila'); ?>
<?php $__env->startSection('header_title', 'Dashboard'); ?>

<?php $__env->startSection('content'); ?>
<!-- Stats Grid -->
<div class="stats-grid">
    <?php if (isset($component)) { $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.stat-card','data' => ['type' => 'person','label' => 'Personas hoy','value' => ''.e($personsToday).'','trend' => '18% vs ayer','trendUp' => true,'icon' => '👥']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('stat-card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'person','label' => 'Personas hoy','value' => ''.e($personsToday).'','trend' => '18% vs ayer','trendUp' => true,'icon' => '👥']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $attributes = $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $component = $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
    <?php if (isset($component)) { $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.stat-card','data' => ['type' => 'vehicle','label' => 'Vehículos hoy','value' => ''.e($vehiclesToday).'','trend' => '12% vs ayer','trendUp' => true,'icon' => '🚗']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('stat-card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'vehicle','label' => 'Vehículos hoy','value' => ''.e($vehiclesToday).'','trend' => '12% vs ayer','trendUp' => true,'icon' => '🚗']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $attributes = $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $component = $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
    <?php if (isset($component)) { $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.stat-card','data' => ['type' => 'delivery','label' => 'Entregas hoy','value' => ''.e($deliveriesToday).'','trend' => '6% vs ayer','trendUp' => true,'icon' => '📦']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('stat-card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'delivery','label' => 'Entregas hoy','value' => ''.e($deliveriesToday).'','trend' => '6% vs ayer','trendUp' => true,'icon' => '📦']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $attributes = $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $component = $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
    <?php if (isset($component)) { $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.stat-card','data' => ['type' => 'total','label' => 'Accesos totales hoy','value' => ''.e($totalToday).'','trend' => '15% vs ayer','trendUp' => true,'icon' => '🚪']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('stat-card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'total','label' => 'Accesos totales hoy','value' => ''.e($totalToday).'','trend' => '15% vs ayer','trendUp' => true,'icon' => '🚪']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $attributes = $__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__attributesOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682)): ?>
<?php $component = $__componentOriginal527fae77f4db36afc8c8b7e9f5f81682; ?>
<?php unset($__componentOriginal527fae77f4db36afc8c8b7e9f5f81682); ?>
<?php endif; ?>
</div>

<!-- Dashboard Grid (Main content split) -->
<div class="dashboard-grid">
    <!-- Left Column: Accesos en tiempo real & Guardias -->
    <div style="display: flex; flex-direction: column; gap: 24px;">
        <!-- Accesos en Tiempo Real -->
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">🚨 Accesos en tiempo real</h3>
                <span class="badge badge-success" style="font-size: 11px;">Actualizado: hace unos segs</span>
            </div>
            <div class="card-body" style="padding: 12px 24px;">
                <div style="display: flex; flex-direction: column; gap: 16px;">
                    <?php $__currentLoopData = $recentLogs->take(4); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div style="display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; border-bottom: 1px solid var(--border-color); &:last-child { border-bottom: none; padding-bottom: 0; }">
                            <div style="display: flex; align-items: center; gap: 16px;">
                                <div class="stat-icon" style="width: 40px; height: 40px; border-radius: 50%; font-size: 18px;">
                                    <?php if($log->type->value === 'person'): ?> 👥 <?php elseif($log->type->value === 'vehicle'): ?> 🚗 <?php else: ?> 📦 <?php endif; ?>
                                </div>
                                <div style="display: flex; flex-direction: column;">
                                    <span style="font-size: 14px; font-weight: 700; color: var(--text-primary);">
                                        <?php if($log->type->value === 'vehicle' && isset($log->vehicle)): ?>
                                            Patente <?php echo e($log->vehicle->plate); ?>

                                        <?php else: ?>
                                            <?php echo e($log->visitor->full_name); ?>

                                        <?php endif; ?>
                                    </span>
                                    <span style="font-size: 12px; color: var(--text-secondary);">
                                        <?php if($log->type->value === 'vehicle' && isset($log->vehicle)): ?>
                                            Conductor: <?php echo e($log->visitor->full_name); ?>

                                        <?php elseif($log->type->value === 'delivery'): ?>
                                            RUT: <?php echo e($log->visitor->rut); ?> - <?php echo e($log->zone->name); ?>

                                        <?php else: ?>
                                            RUT: <?php echo e($log->visitor->rut); ?>

                                        <?php endif; ?>
                                    </span>
                                </div>
                            </div>
                            <div style="text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px;">
                                <span style="font-size: 12px; font-weight: 600; color: var(--text-primary);">
                                    <?php echo e($log->entered_at instanceof \Carbon\Carbon ? $log->entered_at->format('H:i A') : \Carbon\Carbon::parse($log->entered_at)->format('H:i A')); ?>

                                </span>
                                <span class="badge badge-success" style="font-size: 10px; padding: 2px 8px;">
                                    <?php echo e($log->status->label()); ?>

                                </span>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
        </div>

        <!-- Donut Chart & Guardias activos -->
        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 24px;">
            <!-- Donut Chart CSS -->
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">📊 Accesos por tipo</h3>
                </div>
                <div class="card-body" style="display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;">
                    <!-- Donut Chart -->
                    <div style="position: relative; width: 140px; height: 140px; border-radius: 50%; background: conic-gradient(var(--accent-color) 0% <?php echo e($personsPct); ?>%, var(--primary-color) <?php echo e($personsPct); ?>% <?php echo e($personsPct + $vehiclesPct); ?>%, var(--warning-color) <?php echo e($personsPct + $vehiclesPct); ?>% 100%); display: flex; align-items: center; justify-content: center;">
                        <div style="position: absolute; width: 100px; height: 100px; border-radius: 50%; background-color: #FFFFFF; display: flex; flex-direction: column; align-items: center; justify-content: center;">
                            <span style="font-size: 24px; font-weight: 800; color: var(--text-primary);"><?php echo e($totalToday); ?></span>
                            <span style="font-size: 10px; font-weight: 600; color: var(--text-light); text-transform: uppercase;">Total</span>
                        </div>
                    </div>
                    <!-- Legend -->
                    <div style="width: 100%; display: flex; flex-direction: column; gap: 8px; font-size: 12px; font-weight: 600;">
                        <div style="display: flex; align-items: center; justify-content: space-between;">
                            <div style="display: flex; align-items: center; gap: 8px;">
                                <span style="width: 12px; height: 12px; border-radius: 50%; background-color: var(--accent-color); display: inline-block;"></span>
                                <span>Personas (<?php echo e($personsPct); ?>%)</span>
                            </div>
                            <span style="color: var(--text-secondary);"><?php echo e($personsToday); ?></span>
                        </div>
                        <div style="display: flex; align-items: center; justify-content: space-between;">
                            <div style="display: flex; align-items: center; gap: 8px;">
                                <span style="width: 12px; height: 12px; border-radius: 50%; background-color: var(--primary-color); display: inline-block;"></span>
                                <span>Vehículos (<?php echo e($vehiclesPct); ?>%)</span>
                            </div>
                            <span style="color: var(--text-secondary);"><?php echo e($vehiclesToday); ?></span>
                        </div>
                        <div style="display: flex; align-items: center; justify-content: space-between;">
                            <div style="display: flex; align-items: center; gap: 8px;">
                                <span style="width: 12px; height: 12px; border-radius: 50%; background-color: var(--warning-color); display: inline-block;"></span>
                                <span>Entregas (<?php echo e($deliveriesPct); ?>%)</span>
                            </div>
                            <span style="color: var(--text-secondary);"><?php echo e($deliveriesToday); ?></span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Guardias Activos -->
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">👮 Guardias en servicio</h3>
                    <span style="font-size: 20px; font-weight: 800; color: var(--accent-color);"><?php echo e($activeGuards->count()); ?></span>
                </div>
                <div class="card-body" style="padding: 12px 24px;">
                    <div style="display: flex; flex-direction: column; gap: 16px;">
                        <?php $__currentLoopData = $activeGuards; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $guard): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div style="display: flex; align-items: center; justify-content: space-between;">
                                <div style="display: flex; align-items: center; gap: 12px;">
                                    <div style="width: 36px; height: 36px; border-radius: 50%; background-color: #F1F5F9; color: var(--text-primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;">
                                        <?php echo e(substr($guard->name, 0, 1)); ?>

                                    </div>
                                    <div style="display: flex; flex-direction: column;">
                                        <span style="font-size: 13px; font-weight: 700; color: var(--text-primary);"><?php echo e($guard->name); ?></span>
                                        <span style="font-size: 11px; color: var(--text-secondary);"><?php echo e(isset($guard->patrol_zone) ? $guard->patrol_zone : 'Patrullaje General'); ?></span>
                                    </div>
                                </div>
                                <span class="badge badge-success" style="font-size: 10px; padding: 2px 8px;">Activo</span>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Right Column: Recinto Map (Leaflet.js) -->
    <div class="card" style="margin-bottom: 0;">
        <div class="card-header">
            <h3 class="card-title">🗺️ Vista del recinto</h3>
            <select style="padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border-color); font-size: 12px; font-weight: 600; outline: none;" id="map-view-select">
                <option value="all">Ver todas las zonas</option>
            </select>
        </div>
        <div class="card-body" style="padding: 0; position: relative;">
            <div id="recinto-map" class="map-container"></div>
        </div>
    </div>
</div>

<!-- Bottom Section: Accesos Recientes -->
<div class="card">
    <div class="card-header">
        <h3 class="card-title">📝 Accesos recientes</h3>
        <a href="<?php echo e(route('access.index')); ?>" class="btn btn-secondary" style="font-size: 12px; padding: 6px 12px;">Ver todos</a>
    </div>
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th>Hora</th>
                    <th>Tipo</th>
                    <th>Nombre / Descripción</th>
                    <th>Destino / Zona</th>
                    <th>Guardia</th>
                    <th>Estado</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $recentLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td style="font-weight: 600;">
                            <?php echo e($log->entered_at instanceof \Carbon\Carbon ? $log->entered_at->format('H:i A') : \Carbon\Carbon::parse($log->entered_at)->format('H:i A')); ?>

                        </td>
                        <td>
                            <span class="badge <?php echo e($log->type->value === 'person' ? 'badge-info' : ($log->type->value === 'vehicle' ? 'badge-success' : 'badge-warning')); ?>" style="font-size: 11px;">
                                <?php echo e($log->type->label()); ?>

                            </span>
                        </td>
                        <td>
                            <div style="display: flex; flex-direction: column;">
                                <span style="font-weight: 700; color: var(--text-primary);">
                                    <?php if($log->type->value === 'vehicle' && isset($log->vehicle)): ?>
                                        Patente <?php echo e($log->vehicle->plate); ?>

                                    <?php else: ?>
                                        <?php echo e($log->visitor->full_name); ?>

                                    <?php endif; ?>
                                </span>
                                <span style="font-size: 11px; color: var(--text-secondary);">
                                    <?php if($log->type->value === 'vehicle' && isset($log->vehicle)): ?>
                                        Conductor: <?php echo e($log->visitor->full_name); ?>

                                    <?php else: ?>
                                        RUT: <?php echo e($log->visitor->rut); ?>

                                    <?php endif; ?>
                                </span>
                            </div>
                        </td>
                        <td style="font-weight: 600; color: var(--text-secondary);"><?php echo e($log->zone->name); ?></td>
                        <td style="font-weight: 500;"><?php echo e($log->guardUser->name); ?></td>
                        <td>
                            <span class="badge badge-success"><?php echo e($log->status->label()); ?></span>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
</div>

<!-- Map Initialize script -->
<script>
    document.addEventListener("DOMContentLoaded", function() {
        // Inicializar mapa de Leaflet
        // Coordenadas fijas en Santiago de Chile
        var map = L.map('recinto-map').setView([-33.4489, -70.6693], 16);

        // Capa de OpenStreetMap
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            maxZoom: 19,
            attribution: '© OpenStreetMap'
        }).addTo(map);

        // Marcadores de zonas con popup
        var zones = [
            { name: "Entrada Principal", coords: [-33.4485, -70.6700], count: "2 accesos ahora" },
            { name: "Oficinas", coords: [-33.4492, -70.6690], count: "8 personas" },
            { name: "Recepción", coords: [-33.4490, -70.6685], count: "3 entregas en cola" },
            { name: "Estacionamientos", coords: [-33.4483, -70.6688], count: "5 vehículos activos" },
            { name: "Bodega Norte", coords: [-33.4495, -70.6705], count: "1 persona" }
        ];

        zones.forEach(function(zone) {
            L.marker(zone.coords)
             .addTo(map)
             .bindPopup("<b>" + zone.name + "</b><br>" + zone.count);
        });
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\ojodeaguila\resources\views/dashboard.blade.php ENDPATH**/ ?>