

<?php $__env->startSection('title', 'Device Usage Report'); ?>

<?php $__env->startSection('content'); ?>
<div class="content-wrapper">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-1">
                    <li class="breadcrumb-item"><a href="<?php echo e(route('dashboard.reports')); ?>">Reports</a></li>
                    <li class="breadcrumb-item active">Device Usage</li>
                </ol>
            </nav>
            <h4 class="mb-0">Device Usage Report</h4>
        </div>
        <?php if($canExport): ?>
        <a href="<?php echo e(route('dashboard.reports.device-usage.export', request()->query())); ?>" class="btn btn-success">
            <i class="bi bi-file-earmark-excel me-1"></i> Export to Excel
        </a>
        <?php endif; ?>
    </div>

    <!-- Filters -->
    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <form method="GET" action="<?php echo e(route('dashboard.reports.device-usage')); ?>" class="row g-3">
                <div class="col-md-4">
                    <label class="form-label">Date From</label>
                    <input type="date" name="date_from" class="form-control" value="<?php echo e($dateFrom); ?>">
                </div>
                <div class="col-md-4">
                    <label class="form-label">Date To</label>
                    <input type="date" name="date_to" class="form-control" value="<?php echo e($dateTo); ?>">
                </div>
                <div class="col-md-4 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-funnel me-1"></i> Filter
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- Summary Stats -->
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="card border-0 shadow-sm bg-primary bg-opacity-10">
                <div class="card-body text-center">
                    <h3 class="text-primary mb-0"><?php echo e(number_format($summary['total_sessions'])); ?></h3>
                    <small class="text-muted">Total Sessions</small>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm bg-info bg-opacity-10">
                <div class="card-body text-center">
                    <h3 class="text-info mb-0"><?php echo e(number_format($summary['unique_devices'])); ?></h3>
                    <small class="text-muted">Unique Devices</small>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm bg-success bg-opacity-10">
                <div class="card-body text-center">
                    <h3 class="text-success mb-0"><?php echo e(number_format($summary['unique_users'])); ?></h3>
                    <small class="text-muted">Unique Users</small>
                </div>
            </div>
        </div>
    </div>

    <!-- Charts -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-header bg-transparent">
                    <h6 class="mb-0">Device Name Distribution</h6>
                </div>
                <div class="card-body">
                    <canvas id="deviceNameChart" height="250"></canvas>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-header bg-transparent">
                    <h6 class="mb-0">App Version Distribution</h6>
                </div>
                <div class="card-body">
                    <canvas id="appVersionChart" height="250"></canvas>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-header bg-transparent">
                    <h6 class="mb-0">Top Device Models</h6>
                </div>
                <div class="card-body">
                    <canvas id="topDevicesChart" height="250"></canvas>
                </div>
            </div>
        </div>
    </div>

    <!-- Report Table -->
    <div class="card border-0 shadow-sm">
        <div class="card-header bg-transparent">
            <h6 class="mb-0">Device Details</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Device Model</th>
                            <th>Device Name</th>
                            <th>App Version</th>
                            <th class="text-center">Sessions</th>
                            <th class="text-center">Users</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $deviceStats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td>
                                <i class="bi bi-phone me-2 text-muted"></i>
                                <span class="masked-data"><?php echo e($stat->device_model ?? 'Unknown'); ?></span>
                            </td>
                            <td>
                                <span class="badge bg-secondary"><?php echo e($stat->device_name ?? 'N/A'); ?></span>
                            </td>
                            <td>
                                <span class="badge bg-primary">v<?php echo e($stat->app_version ?? 'N/A'); ?></span>
                            </td>
                            <td class="text-center">
                                <span class="badge bg-info"><?php echo e(number_format($stat->session_count)); ?></span>
                            </td>
                            <td class="text-center">
                                <span class="badge bg-success"><?php echo e(number_format($stat->user_count)); ?></span>
                            </td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">No device data found for the selected criteria.</td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

            <div class="d-flex justify-content-center mt-4">
                <?php echo e($deviceStats->appends(request()->query())->links()); ?>

            </div>
        </div>
    </div>
</div>

<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const colors = ['#667eea', '#28a745', '#17a2b8', '#ffc107', '#dc3545', '#6f42c1', '#fd7e14', '#20c997', '#e83e8c', '#6c757d'];

        // Device Name Chart
        const deviceByName = <?php echo json_encode($deviceByName, 15, 512) ?>;
        new Chart(document.getElementById('deviceNameChart'), {
            type: 'pie',
            data: {
                labels: Object.keys(deviceByName),
                datasets: [{
                    data: Object.values(deviceByName),
                    backgroundColor: colors
                }]
            },
            options: {
                responsive: true,
                plugins: {
                    legend: {
                        position: 'bottom',
                        labels: {
                            boxWidth: 12,
                            font: {
                                size: 10
                            }
                        }
                    }
                }
            }
        });

        // App Version Chart
        const appByVersion = <?php echo json_encode($appByVersion, 15, 512) ?>;
        new Chart(document.getElementById('appVersionChart'), {
            type: 'pie',
            data: {
                labels: Object.keys(appByVersion).map(v => 'v' + v),
                datasets: [{
                    data: Object.values(appByVersion),
                    backgroundColor: colors.slice().reverse()
                }]
            },
            options: {
                responsive: true,
                plugins: {
                    legend: {
                        position: 'bottom',
                        labels: {
                            boxWidth: 12,
                            font: {
                                size: 10
                            }
                        }
                    }
                }
            }
        });

        // Top Devices Chart
        const topDevices = <?php echo json_encode($topDevices, 15, 512) ?>;
        new Chart(document.getElementById('topDevicesChart'), {
            type: 'bar',
            data: {
                labels: Object.keys(topDevices),
                datasets: [{
                    label: 'Users',
                    data: Object.values(topDevices),
                    backgroundColor: colors
                }]
            },
            options: {
                indexAxis: 'y',
                responsive: true,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    x: {
                        beginAtZero: true
                    }
                }
            }
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp82\htdocs\AutoPromix\backend\resources\views\dashboard\reports\device-usage.blade.php ENDPATH**/ ?>