

<?php $__env->startSection('title', 'Message Logs'); ?>

<?php $__env->startSection('styles'); ?>
<style>
    .channel-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 3px 8px;
        border-radius: 20px;
        font-size: 0.72rem;
        font-weight: 600;
    }
    .channel-sms { background: #e3f2fd; color: #1565c0; }
    .channel-whatsapp { background: #e8f5e9; color: #128C7E; }
</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h4 class="mb-1">Message Logs</h4>
        <p class="text-muted mb-0">View all SMS &amp; WhatsApp activity from your organization's users</p>
    </div>
    <a href="<?php echo e(route('client.sms-logs.export', request()->query())); ?>" class="btn btn-success">
        <i class="bi bi-file-earmark-excel me-1"></i> Export Excel
    </a>
</div>

<!-- Stats Row -->
<div class="row g-3 mb-4">
    <div class="col-6 col-md">
        <div class="stat-card text-center">
            <div class="stat-value text-primary"><?php echo e($stats['total']); ?></div>
            <div class="stat-label">Total Messages</div>
        </div>
    </div>
    <div class="col-6 col-md">
        <div class="stat-card text-center">
            <div class="stat-value text-success"><?php echo e($stats['sent']); ?></div>
            <div class="stat-label">Sent</div>
        </div>
    </div>
    <div class="col-6 col-md">
        <div class="stat-card text-center">
            <div class="stat-value text-warning"><?php echo e($stats['pending']); ?></div>
            <div class="stat-label">Pending</div>
        </div>
    </div>
    <div class="col-6 col-md">
        <div class="stat-card text-center">
            <div class="stat-value text-danger"><?php echo e($stats['failed']); ?></div>
            <div class="stat-label">Failed</div>
        </div>
    </div>
    <div class="col-6 col-md">
        <div class="stat-card text-center">
            <div class="stat-value" style="color:#1565c0"><?php echo e($stats['sms_total']); ?></div>
            <div class="stat-label"><i class="bi bi-chat-dots me-1"></i>SMS</div>
        </div>
    </div>
    <div class="col-6 col-md">
        <div class="stat-card text-center">
            <div class="stat-value" style="color:#128C7E"><?php echo e($stats['whatsapp_total']); ?></div>
            <div class="stat-label"><i class="bi bi-whatsapp me-1"></i>WhatsApp</div>
        </div>
    </div>
</div>

<!-- Filters -->
<div class="table-card mb-4">
    <div class="card-body p-3">
        <form method="GET" action="<?php echo e(route('client.sms-logs')); ?>" class="row g-2 align-items-end">
            <div class="col-md-2">
                <input type="text" class="form-control form-control-sm" name="search" placeholder="Search phone..." value="<?php echo e(request('search')); ?>">
            </div>
            <div class="col-md-2">
                <select class="form-select form-select-sm" name="user_id">
                    <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(request('user_id') == $user->id ? 'selected' : ''); ?>><?php echo e($user->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-2">
                <select class="form-select form-select-sm" name="channel">
                    <option value="">All Channels</option>
                    <option value="sms" <?php echo e(request('channel') === 'sms' ? 'selected' : ''); ?>>SMS</option>
                    <option value="whatsapp" <?php echo e(request('channel') === 'whatsapp' ? 'selected' : ''); ?>>WhatsApp</option>
                </select>
            </div>
            <div class="col-md-2">
                <select class="form-select form-select-sm" name="status">
                    <option value="">All Status</option>
                    <option value="sent" <?php echo e(request('status') === 'sent' ? 'selected' : ''); ?>>Sent</option>
                    <option value="pending" <?php echo e(request('status') === 'pending' ? 'selected' : ''); ?>>Pending</option>
                    <option value="failed" <?php echo e(request('status') === 'failed' ? 'selected' : ''); ?>>Failed</option>
                </select>
            </div>
            <div class="col-md-2">
                <input type="date" class="form-control form-control-sm" name="date_from" value="<?php echo e(request('date_from')); ?>">
            </div>
            <div class="col-md-1">
                <input type="date" class="form-control form-control-sm" name="date_to" value="<?php echo e(request('date_to')); ?>">
            </div>
            <div class="col-md-1 d-flex gap-1">
                <button type="submit" class="btn btn-primary btn-sm flex-fill">
                    <i class="bi bi-funnel"></i>
                </button>
                <a href="<?php echo e(route('client.sms-logs')); ?>" class="btn btn-outline-secondary btn-sm" title="Clear">
                    <i class="bi bi-x-lg"></i>
                </a>
            </div>
        </form>
    </div>
</div>

<!-- Message Logs Table -->
<div class="table-card">
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th>User</th>
                    <th>Phone Number</th>
                    <th>Channel</th>
                    <th>Message Type</th>
                    <th>Status</th>
                    <th>Type</th>
                    <th>Time</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $smsLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td>
                        <div class="d-flex align-items-center gap-2">
                            <div class="rounded-circle bg-primary text-white d-flex align-items-center justify-content-center" style="width: 32px; height: 32px; font-size: 0.75rem;">
                                <?php echo e(strtoupper(substr($log->user->name ?? 'U', 0, 1))); ?>

                            </div>
                            <span><?php echo e($log->user->name ?? 'Unknown'); ?></span>
                        </div>
                    </td>
                    <td>
                        <code><?php echo e($log->phone_number); ?></code>
                        <?php if($log->contact_name): ?>
                        <br><small class="text-muted"><?php echo e($log->contact_name); ?></small>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($log->channel === 'whatsapp'): ?>
                            <span class="channel-badge channel-whatsapp">
                                <i class="bi bi-whatsapp"></i> WhatsApp
                            </span>
                        <?php else: ?>
                            <span class="channel-badge channel-sms">
                                <i class="bi bi-chat-dots"></i> SMS
                            </span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($log->sms_type === 'auto_reply'): ?>
                        <span class="badge bg-info">Auto Reply</span>
                        <?php elseif($log->sms_type === 'promotion'): ?>
                        <span class="badge bg-warning text-dark">Promotion</span>
                        <?php else: ?>
                        <span class="badge bg-secondary"><?php echo e(ucfirst(str_replace('_', ' ', $log->sms_type ?? 'unknown'))); ?></span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($log->status === 'sent'): ?>
                        <span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>Sent</span>
                        <?php elseif($log->status === 'pending'): ?>
                        <span class="badge bg-warning"><i class="bi bi-clock me-1"></i>Pending</span>
                        <?php else: ?>
                        <span class="badge bg-danger"><i class="bi bi-x-circle me-1"></i>Failed</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($log->sms_type === 'incoming'): ?>
                        <span class="badge bg-info">Incoming</span>
                        <?php else: ?>
                        <span class="badge bg-primary">Outgoing</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <small class="text-muted">
                            <?php echo e($log->created_at->format('M d, Y')); ?><br>
                            <?php echo e($log->created_at->format('h:i A')); ?>

                        </small>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr>
                    <td colspan="7" class="text-center py-5">
                        <div class="text-muted mb-3">
                            <i class="bi bi-chat-dots" style="font-size: 3rem;"></i>
                        </div>
                        <p class="mb-0">No message logs found</p>
                    </td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>

    <?php if($smsLogs->hasPages()): ?>
    <div class="card-footer bg-transparent">
        <?php echo e($smsLogs->withQueryString()->links()); ?>

    </div>
    <?php endif; ?>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('client.layouts.dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp82\htdocs\AutoPromix\backend\resources\views/client/reports/sms-logs.blade.php ENDPATH**/ ?>