

<?php $__env->startSection('title', 'SMS Summary 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">SMS Summary</li>
                </ol>
            </nav>
            <h4 class="mb-0">SMS Summary Report</h4>
        </div>
        <?php if($canExport): ?>
        <a href="<?php echo e(route('dashboard.reports.sms-summary.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.sms-summary')); ?>" class="row g-3">
                <div class="col-md-2">
                    <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-2">
                    <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-2">
                    <label class="form-label">Status</label>
                    <select name="status" class="form-select">
                        <option value="">All Status</option>
                        <option value="sent" <?php echo e($status == 'sent' ? 'selected' : ''); ?>>Sent</option>
                        <option value="delivered" <?php echo e($status == 'delivered' ? 'selected' : ''); ?>>Delivered</option>
                        <option value="failed" <?php echo e($status == 'failed' ? 'selected' : ''); ?>>Failed</option>
                        <option value="pending" <?php echo e($status == 'pending' ? 'selected' : ''); ?>>Pending</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <label class="form-label">User</label>
                    <select name="user_id" class="form-select">
                        <option value="">All Users</option>
                        <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($user->id); ?>" <?php echo e($userId == $user->id ? 'selected' : ''); ?>>
                            <?php echo e($user->name); ?>

                        </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary w-100">
                        <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-2">
            <div class="card border-0 shadow-sm">
                <div class="card-body text-center">
                    <h3 class="text-primary mb-0"><?php echo e(number_format($summary['total'])); ?></h3>
                    <small class="text-muted">Total SMS</small>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <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['sent'])); ?></h3>
                    <small class="text-muted">Sent</small>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <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['delivered'])); ?></h3>
                    <small class="text-muted">Delivered</small>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <div class="card border-0 shadow-sm bg-danger bg-opacity-10">
                <div class="card-body text-center">
                    <h3 class="text-danger mb-0"><?php echo e(number_format($summary['failed'])); ?></h3>
                    <small class="text-muted">Failed</small>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <div class="card border-0 shadow-sm bg-warning bg-opacity-10">
                <div class="card-body text-center">
                    <h3 class="text-warning mb-0"><?php echo e(number_format($summary['pending'])); ?></h3>
                    <small class="text-muted">Pending</small>
                </div>
            </div>
        </div>
    </div>

    <!-- Chart -->
    <div class="row g-4 mb-4">
        <div class="col-md-8">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-transparent">
                    <h6 class="mb-0">SMS Trend</h6>
                </div>
                <div class="card-body">
                    <canvas id="smsTrendChart" height="120"></canvas>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-transparent">
                    <h6 class="mb-0">Status Distribution</h6>
                </div>
                <div class="card-body">
                    <canvas id="smsStatusChart" height="200"></canvas>
                </div>
            </div>
        </div>
    </div>

    <!-- Report Table -->
    <div class="card border-0 shadow-sm">
        <div class="card-header bg-transparent">
            <h6 class="mb-0">SMS Details</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>User</th>
                            <?php if($isSuperAdmin): ?>
                            <th>Phone Number</th>
                            <?php endif; ?>
                            <th>Status</th>
                            <th>Call Type</th>
                            <th>Message</th>
                            <th>Sent At</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $report; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($log->id); ?></td>
                            <td><?php echo e($log->user->name ?? 'N/A'); ?></td>
                            <?php if($isSuperAdmin): ?>
                            <td><span class="masked-data"><?php echo e($log->phone_number); ?></span></td>
                            <?php endif; ?>
                            <td>
                                <?php switch(strtoupper($log->status)):
                                case ('SENT'): ?>
                                <span class="badge badge-sent">Sent</span>
                                <?php break; ?>
                                <?php case ('DELIVERED'): ?>
                                <span class="badge bg-info">Delivered</span>
                                <?php break; ?>
                                <?php case ('FAILED'): ?>
                                <span class="badge badge-failed">Failed</span>
                                <?php break; ?>
                                <?php case ('PENDING'): ?>
                                <span class="badge badge-pending">Pending</span>
                                <?php break; ?>
                                <?php default: ?>
                                <span class="badge bg-secondary"><?php echo e($log->status); ?></span>
                                <?php endswitch; ?>
                            </td>
                            <td>
                                <?php if($log->callLog): ?>
                                <?php switch(strtoupper($log->callLog->call_type)):
                                case ('INCOMING'): ?>
                                <span class="badge badge-incoming">Incoming</span>
                                <?php break; ?>
                                <?php case ('OUTGOING'): ?>
                                <span class="badge badge-outgoing">Outgoing</span>
                                <?php break; ?>
                                <?php case ('MISSED'): ?>
                                <span class="badge badge-missed">Missed</span>
                                <?php break; ?>
                                <?php case ('REJECTED'): ?>
                                <span class="badge bg-secondary">Rejected</span>
                                <?php break; ?>
                                <?php default: ?>
                                <span class="badge bg-secondary"><?php echo e($log->callLog->call_type); ?></span>
                                <?php endswitch; ?>
                                <?php else: ?>
                                <span class="badge bg-light text-muted">N/A</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span class="text-truncate d-inline-block" style="max-width: 250px;" title="<?php echo e($log->message); ?>">
                                    <?php echo e($log->message); ?>

                                </span>
                            </td>
                            <td><?php echo e(\Carbon\Carbon::parse($log->sent_at)->format('Y-m-d H:i:s')); ?></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="<?php echo e($isSuperAdmin ? 7 : 6); ?>" class="text-center text-muted py-4">No SMS found for the selected criteria.</td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

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

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

<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // SMS Trend Chart
        const smsByDay = <?php echo json_encode($smsByDay, 15, 512) ?>;
        const labels = Object.keys(smsByDay);
        const data = Object.values(smsByDay);

        new Chart(document.getElementById('smsTrendChart'), {
            type: 'line',
            data: {
                labels: labels,
                datasets: [{
                    label: 'SMS Count',
                    data: data,
                    borderColor: '#28a745',
                    backgroundColor: 'rgba(40, 167, 69, 0.1)',
                    fill: true,
                    tension: 0.4
                }]
            },
            options: {
                responsive: true,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });

        // Status Distribution Chart
        const smsByStatus = <?php echo json_encode($smsByStatus, 15, 512) ?>;
        new Chart(document.getElementById('smsStatusChart'), {
            type: 'doughnut',
            data: {
                labels: Object.keys(smsByStatus).map(s => s.charAt(0).toUpperCase() + s.slice(1)),
                datasets: [{
                    data: Object.values(smsByStatus),
                    backgroundColor: ['#28a745', '#17a2b8', '#dc3545', '#ffc107']
                }]
            },
            options: {
                responsive: true,
                plugins: {
                    legend: {
                        position: 'bottom'
                    }
                }
            }
        });
    });
</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\sms-summary.blade.php ENDPATH**/ ?>