<?php $__env->startSection('title', 'Dashboard'); ?>
<?php $__env->startSection('subtitle', 'Track visitors, manage responses, and keep the site profile healthy from one compact workspace.'); ?>

<?php $__env->startSection('content'); ?>
    <?php
        $lateThreshold = now()->subHours(24);
    ?>

    <section class="admin-grid admin-grid--stats">
        <?php $__currentLoopData = $stats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php echo $__env->make('admin.partials.stat-card', $stat, array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </section>

    <section class="mt-6 admin-fiverr-grid">
        <div class="admin-card admin-card--feature">
            <div class="admin-toolbar">
                <div>
                    <p class="admin-section-title">Manage Responses</p>
                </div>
                <a href="<?php echo e(route('admin.contacts.index')); ?>" class="admin-button admin-button--secondary">Open inbox</a>
            </div>

            <div class="admin-response-tabs">
                <?php $__currentLoopData = $response_statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <a href="<?php echo e(route('admin.contacts.index', ['status' => $status['class'] === 'late' ? 'late' : $status['class']])); ?>" class="admin-response-tab admin-response-tab--<?php echo e($status['class']); ?>">
                        <span><?php echo e($status['label']); ?></span>
                        <strong><?php echo e($status['value']); ?></strong>
                    </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            <div class="admin-response-table">
                <table>
                    <thead>
                        <tr>
                            <th>Visitor</th>
                            <th>Received</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $recent_contacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contact): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $isLate = in_array($contact->status, ['new', 'read'], true) && $contact->created_at->lte($lateThreshold);
                                $statusLabel = $isLate ? 'Late' : ucfirst($contact->status);
                                $statusClass = $isLate ? 'late' : $contact->status;
                            ?>
                            <tr>
                                <td>
                                    <div class="admin-table-person">
                                        <strong><?php echo e($contact->name); ?></strong>
                                        <span><?php echo e($contact->email); ?></span>
                                        <p><?php echo e(\Illuminate\Support\Str::limit($contact->message, 72)); ?></p>
                                    </div>
                                </td>
                                <td><?php echo e($contact->created_at->diffForHumans()); ?></td>
                                <td><span class="admin-badge admin-badge--<?php echo e($statusClass); ?>"><?php echo e($statusLabel); ?></span></td>
                                <td><a href="<?php echo e(route('admin.contacts.show', $contact)); ?>" class="admin-button admin-button--ghost">Review</a></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="4" class="admin-empty">No contact messages yet.</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="admin-sidebar-stack">
            <div class="admin-card">
                <div class="admin-toolbar">
                    <div>
                        <p class="admin-section-title">Profile Strength</p>
                        <p class="admin-section-subtitle">Complete the brand setup so the CMS is ready for clients and leads.</p>
                    </div>
                    <span class="admin-score"><?php echo e($profile_strength['completed']); ?>/<?php echo e($profile_strength['total']); ?></span>
                </div>

                <div class="admin-progress">
                    <span class="admin-progress__bar" style="width: <?php echo e($profile_strength['percent']); ?>%"></span>
                </div>

                <div class="admin-checklist">
                    <?php $__currentLoopData = $profile_strength['items']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $label => $completed): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="admin-checklist__item">
                            <span class="admin-checklist__dot <?php echo e($completed ? 'is-complete' : ''); ?>"></span>
                            <span><?php echo e($label); ?></span>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>

                <a href="<?php echo e(route('profile.edit')); ?>" class="admin-button mt-4">Complete profile</a>
            </div>

            <div class="admin-card">
                <div class="admin-toolbar">
                    <div>
                        <p class="admin-section-title">Track Your Performance</p>
                        <p class="admin-section-subtitle">Quick system totals and traffic hotspots.</p>
                    </div>
                </div>

                <div class="admin-mini-stats">
                    <?php $__currentLoopData = $site_totals; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="admin-mini-stat">
                            <span><?php echo e($item['label']); ?></span>
                            <strong><?php echo e($item['value']); ?></strong>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>

                <div class="admin-list mt-4">
                    <?php $__empty_1 = true; $__currentLoopData = $top_countries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $country): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="admin-list__item">
                            <div>
                                <p class="font-semibold"><?php echo e($country['country']); ?></p>
                                <p class="text-sm text-slate-500"><?php echo e($country['unique']); ?> unique visitors</p>
                            </div>
                            <span class="admin-chip"><?php echo e($country['visits']); ?> visits</span>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <div class="admin-empty">Country data will appear after visitors browse the public site.</div>
                    <?php endif; ?>
                </div>

                <div class="mt-5">
                    <p class="admin-section-title">Traffic sources</p>
                    <div class="admin-list mt-3">
                        <?php $__empty_1 = true; $__currentLoopData = $top_sources; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $source): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <div class="admin-list__item">
                                <div>
                                    <p class="font-semibold"><?php echo e(ucfirst($source['source'])); ?></p>
                                    <p class="text-sm text-slate-500"><?php echo e(ucfirst($source['medium'])); ?> | <?php echo e($source['unique']); ?> unique visitors</p>
                                </div>
                                <span class="admin-chip"><?php echo e($source['visits']); ?> visits</span>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <div class="admin-empty">Source tracking appears after users arrive from search, campaigns, or referrals.</div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="mt-6 admin-grid admin-grid--three">
        <div class="admin-card admin-chart-card">
            <div class="admin-toolbar">
                <div>
                    <p class="admin-section-title">Visitor Trend</p>
                    <p class="admin-section-subtitle">Compact 7-day view of visits and unique visitors.</p>
                </div>
            </div>
            <div class="admin-chart-canvas">
                <canvas id="visitsChart" height="96"></canvas>
            </div>
        </div>

        <div class="admin-card">
            <div class="admin-toolbar">
                <div>
                    <p class="admin-section-title">Top Pages</p>
                    <p class="admin-section-subtitle">Which public URLs are attracting attention.</p>
                </div>
            </div>

            <div class="admin-list">
                <?php $__empty_1 = true; $__currentLoopData = $top_pages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="admin-list__item">
                        <div>
                            <p class="font-semibold"><?php echo e($page['path']); ?></p>
                            <p class="text-sm text-slate-500"><?php echo e($page['unique']); ?> unique visitors</p>
                        </div>
                        <span class="admin-chip"><?php echo e($page['visits']); ?> visits</span>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="admin-empty">No visit data yet.</div>
                <?php endif; ?>
            </div>
        </div>

        <div class="admin-card">
            <div class="admin-toolbar">
                <div>
                    <p class="admin-section-title">Recent Activity</p>
                    <p class="admin-section-subtitle">Last saved records across the CMS.</p>
                </div>
            </div>

            <div class="admin-list">
                <?php $__empty_1 = true; $__currentLoopData = $recent_activity; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $activity): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="admin-list__item">
                        <div>
                            <p class="font-semibold"><?php echo e(class_basename($activity->auditable_type)); ?> <?php echo e($activity->event); ?></p>
                            <p class="text-sm text-slate-500"><?php echo e($activity->user?->name ?? 'System'); ?> on <?php echo e($activity->created_at->format('M j, Y g:i A')); ?></p>
                        </div>
                        <span class="admin-chip">#<?php echo e($activity->auditable_id); ?></span>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="admin-empty">No audit activity found yet.</div>
                <?php endif; ?>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('head'); ?>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<?php $__env->stopPush(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        const ctx = document.getElementById('visitsChart');

        if (ctx) {
            new Chart(ctx, {
                type: 'line',
                data: {
                    labels: <?php echo json_encode($visits_chart['labels'], 15, 512) ?>,
                    datasets: [
                        {
                            label: <?php echo json_encode($visits_chart['datasets'][0]['label'], 15, 512) ?>,
                            data: <?php echo json_encode($visits_chart['datasets'][0]['data'], 15, 512) ?>,
                            borderColor: '#1dbf73',
                            backgroundColor: 'rgba(29, 191, 115, 0.12)',
                            tension: 0.35,
                            fill: true,
                            borderWidth: 2,
                        },
                        {
                            label: <?php echo json_encode($visits_chart['datasets'][1]['label'], 15, 512) ?>,
                            data: <?php echo json_encode($visits_chart['datasets'][1]['data'], 15, 512) ?>,
                            borderColor: '#2563eb',
                            backgroundColor: 'rgba(37, 99, 235, 0.08)',
                            tension: 0.35,
                            fill: true,
                            borderWidth: 2,
                        }
                    ],
                },
                options: {
                    maintainAspectRatio: false,
                    plugins: {
                        legend: {
                            position: 'bottom',
                        }
                    },
                    scales: {
                        y: {
                            beginAtZero: true,
                            ticks: {
                                precision: 0,
                            }
                        }
                    }
                }
            });
        }
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/xsoftdev/saleemsail.xsoftdevelop.com/resources/views/admin/dashboard.blade.php ENDPATH**/ ?>