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

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h4 class="mb-1">Call Logs</h4>
        <p class="text-muted mb-0">View all call activity from your organization's users</p>
    </div>
    <a href="<?php echo e(route('client.call-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-md-3">
        <div class="stat-card text-center">
            <div class="stat-value text-primary"><?php echo e($stats['total']); ?></div>
            <div class="stat-label">Total Calls</div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="stat-card text-center">
            <div class="stat-value text-success"><?php echo e($stats['incoming']); ?></div>
            <div class="stat-label">Incoming</div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="stat-card text-center">
            <div class="stat-value text-primary"><?php echo e($stats['outgoing']); ?></div>
            <div class="stat-label">Outgoing</div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="stat-card text-center">
            <div class="stat-value text-danger"><?php echo e($stats['missed']); ?></div>
            <div class="stat-label">Missed</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.call-logs')); ?>" class="row g-3">
            <div class="col-md-3">
                <input type="text" class="form-control" name="search" placeholder="Search phone number..." value="<?php echo e(request('search')); ?>">
            </div>
            <div class="col-md-2">
                <select class="form-select" 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" name="type">
                    <option value="">All Types</option>
                    <option value="incoming" <?php echo e(request('type') === 'incoming' ? 'selected' : ''); ?>>Incoming</option>
                    <option value="outgoing" <?php echo e(request('type') === 'outgoing' ? 'selected' : ''); ?>>Outgoing</option>
                    <option value="missed" <?php echo e(request('type') === 'missed' ? 'selected' : ''); ?>>Missed</option>
                </select>
            </div>
            <div class="col-md-2">
                <select class="form-select" name="status_key">
                    <option value="">All Statuses</option>
                    <?php $__currentLoopData = ($statusOptions ?? []); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($key); ?>" <?php echo e(request('status_key') === $key ? 'selected' : ''); ?>><?php echo e($label); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-2">
                <input type="date" class="form-control" name="date_from" value="<?php echo e(request('date_from')); ?>" placeholder="From Date">
            </div>
            <div class="col-md-2">
                <input type="date" class="form-control" name="date_to" value="<?php echo e(request('date_to')); ?>" placeholder="To Date">
            </div>
            <div class="col-md-2 d-flex align-items-center">
                <div class="form-check mt-1">
                    <input class="form-check-input" type="checkbox" name="has_note" value="1" id="client_has_note" <?php echo e(request('has_note') ? 'checked' : ''); ?>>
                    <label class="form-check-label small" for="client_has_note">Only with notes</label>
                </div>
            </div>
            <div class="col-md-1">
                <button type="submit" class="btn btn-primary w-100">
                    <i class="bi bi-funnel"></i>
                </button>
            </div>
        </form>
    </div>
</div>

<!-- Call Logs Table -->
<div class="table-card">
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th>User</th>
                    <th>Phone Number</th>
                    <th>Type</th>
                    <th>Status</th>
                    <th>Note</th>
                    <th>Duration</th>
                    <th>Auto-Reply</th>
                    <th>Time</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $callLogs; $__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-success 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->call_type === 'incoming'): ?>
                        <span class="badge bg-info"><i class="bi bi-telephone-inbound me-1"></i>Incoming</span>
                        <?php elseif($log->call_type === 'outgoing'): ?>
                        <span class="badge bg-primary"><i class="bi bi-telephone-outbound me-1"></i>Outgoing</span>
                        <?php else: ?>
                        <span class="badge bg-danger"><i class="bi bi-telephone-x me-1"></i>Missed</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($log->status_label): ?>
                        <span class="badge bg-<?php echo e($log->status_badge_class); ?>"><?php echo e($log->status_label); ?></span>
                        <?php else: ?>
                        <span class="text-muted">—</span>
                        <?php endif; ?>
                    </td>
                    <td style="max-width: 220px; white-space: normal;">
                        <?php echo e($log->status_note ?: '—'); ?>

                    </td>
                    <td>
                        <?php if($log->call_duration): ?>
                        <span class="badge bg-light text-dark">
                            <i class="bi bi-clock me-1"></i><?php echo e(gmdate('H:i:s', $log->call_duration)); ?>

                        </span>
                        <?php else: ?>
                        <span class="text-muted">-</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($log->sms_sent): ?>
                        <span class="badge bg-success"><i class="bi bi-check me-1"></i>Sent</span>
                        <?php else: ?>
                        <span class="badge bg-secondary">No</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <small class="text-muted">
                            <?php echo e(optional($log->call_time)->format('M d, Y') ?? $log->created_at->format('M d, Y')); ?><br>
                            <?php echo e(optional($log->call_time)->format('h:i A') ?? $log->created_at->format('h:i A')); ?>

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

    <?php if($callLogs->hasPages()): ?>
    <div class="card-footer bg-transparent">
        <?php echo e($callLogs->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 /home/zwfgftjb/autopromix.byteengine.in/resources/views/client/reports/call-logs.blade.php ENDPATH**/ ?>