<?php $__env->startSection('title', 'User Details'); ?>

<?php $__env->startSection('styles'); ?>
<style>
    .channel-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 2px 7px;
        border-radius: 20px;
        font-size: 0.7rem;
        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="mb-4">
    <a href="<?php echo e(route('client.users')); ?>" class="text-decoration-none">
        <i class="bi bi-arrow-left me-2"></i>Back to Users
    </a>
</div>

<div class="row g-4">
    <!-- User Info -->
    <div class="col-lg-4">
        <div class="table-card">
            <div class="card-body p-4 text-center">
                <div class="rounded-circle bg-primary text-white d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 80px; height: 80px; font-size: 2rem;">
                    <?php echo e(strtoupper(substr($user->name, 0, 1))); ?>

                </div>
                <h5 class="mb-1"><?php echo e($user->name); ?></h5>
                <p class="text-muted mb-3"><?php echo e($user->email); ?></p>

                <div class="d-flex justify-content-center gap-2 mb-3">
                    <?php if($user->approval_status === 'pending'): ?>
                    <span class="badge badge-pending px-3 py-2">
                        <i class="bi bi-clock me-1"></i>Pending Approval
                    </span>
                    <?php elseif($user->approval_status === 'approved'): ?>
                    <span class="badge badge-approved px-3 py-2">
                        <i class="bi bi-check-circle me-1"></i>Approved
                    </span>
                    <?php else: ?>
                    <span class="badge badge-rejected px-3 py-2">
                        <i class="bi bi-x-circle me-1"></i>Rejected
                    </span>
                    <?php endif; ?>

                    <?php if($user->is_active): ?>
                    <span class="badge bg-success px-3 py-2">Active</span>
                    <?php else: ?>
                    <span class="badge bg-secondary px-3 py-2">Inactive</span>
                    <?php endif; ?>
                </div>

                <div class="border-top pt-3">
                    <div class="row text-start small">
                        <div class="col-6">
                            <div class="text-muted">Phone</div>
                            <div class="fw-medium"><?php echo e($user->phone ?? '-'); ?></div>
                        </div>
                        <div class="col-6">
                            <div class="text-muted">SMS Service</div>
                            <div class="fw-medium">
                                <?php if($user->sms_service_enabled): ?>
                                <span class="text-success"><i class="bi bi-check-circle me-1"></i>Enabled</span>
                                <?php else: ?>
                                <span class="text-secondary"><i class="bi bi-x-circle me-1"></i>Disabled</span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">WhatsApp Service</div>
                            <div class="fw-medium">
                                <?php if($user->settings && $user->settings->whatsapp_enabled): ?>
                                <span class="text-success"><i class="bi bi-whatsapp me-1"></i>Enabled</span>
                                <?php else: ?>
                                <span class="text-secondary"><i class="bi bi-whatsapp me-1"></i>Disabled</span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Preferred Channel</div>
                            <div class="fw-medium">
                                <?php echo e(ucfirst($user->settings->preferred_channel ?? 'sms')); ?>

                            </div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Joined</div>
                            <div class="fw-medium"><?php echo e($user->created_at->format('M d, Y')); ?></div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Last Active</div>
                            <div class="fw-medium"><?php echo e($user->last_active_at ? $user->last_active_at->diffForHumans() : 'Never'); ?></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card-footer bg-transparent">
                <div class="d-grid gap-2">
                    <form method="POST" action="<?php echo e(route('client.users.toggle-status', $user->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-<?php echo e($user->is_active ? 'warning' : 'success'); ?> w-100">
                            <i class="bi bi-<?php echo e($user->is_active ? 'pause' : 'play'); ?> me-2"></i>
                            <?php echo e($user->is_active ? 'Deactivate User' : 'Activate User'); ?>

                        </button>
                    </form>
                    <form method="POST" action="<?php echo e(route('client.users.toggle-sms', $user->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-outline-<?php echo e($user->sms_service_enabled ? 'secondary' : 'primary'); ?> w-100">
                            <i class="bi bi-chat-dots me-2"></i>
                            <?php echo e($user->sms_service_enabled ? 'Disable SMS Service' : 'Enable SMS Service'); ?>

                        </button>
                    </form>
                    <form method="POST" action="<?php echo e(route('client.users.toggle-whatsapp', $user->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-outline-<?php echo e(($user->settings && $user->settings->whatsapp_enabled) ? 'secondary' : 'success'); ?> w-100">
                            <i class="bi bi-whatsapp me-2"></i>
                            <?php echo e(($user->settings && $user->settings->whatsapp_enabled) ? 'Disable WhatsApp Service' : 'Enable WhatsApp Service'); ?>

                        </button>
                    </form>
                    <hr class="my-1">
                    <form method="POST" action="<?php echo e(route('client.users.force-logout', $user->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-outline-danger w-100"
                            data-confirm="Force logout <?php echo e($user->name); ?> from their active device?"
                            data-confirm-title="Force Logout"
                            data-confirm-btn="Force Logout"
                            data-confirm-class="btn-danger">
                            <i class="bi bi-box-arrow-right me-2"></i>Force Logout
                        </button>
                    </form>
                    <form method="POST" action="<?php echo e(route('client.users.reset-password', $user->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-outline-warning w-100"
                            data-confirm="Reset password for <?php echo e($user->name); ?>?"
                            data-confirm-title="Reset Password"
                            data-confirm-btn="Reset Password"
                            data-confirm-class="btn-warning">
                            <i class="bi bi-key me-2"></i>Reset Password
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <?php if($user->approval_status === 'rejected' && $user->rejection_reason): ?>
        <div class="table-card mt-3">
            <div class="card-body">
                <h6 class="text-danger mb-2"><i class="bi bi-exclamation-triangle me-2"></i>Rejection Reason</h6>
                <p class="mb-0 small"><?php echo e($user->rejection_reason); ?></p>
            </div>
        </div>
        <?php endif; ?>
    </div>

    <!-- Activity & Stats -->
    <div class="col-lg-8">
        <!-- Stats Cards -->
        <div class="row g-3 mb-4">
            <div class="col-6 col-md-3">
                <div class="stat-card text-center">
                    <div class="stat-value text-primary"><?php echo e($stats['total_sms']); ?></div>
                    <div class="stat-label"><i class="bi bi-chat-dots me-1"></i>Total SMS</div>
                </div>
            </div>
            <div class="col-6 col-md-3">
                <div class="stat-card text-center">
                    <div class="stat-value" style="color:#128C7E"><?php echo e($stats['total_whatsapp']); ?></div>
                    <div class="stat-label"><i class="bi bi-whatsapp me-1"></i>WhatsApp</div>
                </div>
            </div>
            <div class="col-6 col-md-3">
                <div class="stat-card text-center">
                    <div class="stat-value text-success"><?php echo e($stats['total_calls']); ?></div>
                    <div class="stat-label"><i class="bi bi-telephone me-1"></i>Total Calls</div>
                </div>
            </div>
            <div class="col-6 col-md-3">
                <div class="stat-card text-center">
                    <div class="stat-value text-info"><?php echo e($stats['active_days']); ?></div>
                    <div class="stat-label"><i class="bi bi-calendar-check me-1"></i>Active Days</div>
                </div>
            </div>
        </div>

        <!-- Recent Message Logs (SMS + WhatsApp) -->
        <div class="table-card mb-4">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="bi bi-chat-dots me-2"></i>Recent Message Logs</h5>
            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Phone</th>
                            <th>Channel</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Time</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $recentSms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sms): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($sms->phone_number); ?></td>
                            <td>
                                <?php if($sms->channel === 'whatsapp'): ?>
                                    <span class="channel-badge channel-whatsapp">
                                        <i class="bi bi-whatsapp"></i> WA
                                    </span>
                                <?php else: ?>
                                    <span class="channel-badge channel-sms">
                                        <i class="bi bi-chat-dots"></i> SMS
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if($sms->sms_type === 'auto_reply'): ?>
                                <span class="badge bg-info">Auto Reply</span>
                                <?php elseif($sms->sms_type === 'promotion'): ?>
                                <span class="badge bg-warning">Promotion</span>
                                <?php else: ?>
                                <span class="badge bg-secondary"><?php echo e(ucfirst(str_replace('_', ' ', $sms->sms_type ?? 'unknown'))); ?></span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if($sms->status === 'sent'): ?>
                                <span class="badge bg-success">Sent</span>
                                <?php elseif($sms->status === 'pending'): ?>
                                <span class="badge bg-warning">Pending</span>
                                <?php else: ?>
                                <span class="badge bg-danger">Failed</span>
                                <?php endif; ?>
                            </td>
                            <td><small class="text-muted"><?php echo e($sms->created_at->diffForHumans()); ?></small></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">No message logs yet</td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Recent Call Logs -->
        <div class="table-card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="bi bi-telephone me-2"></i>Recent Call Logs</h5>
            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Phone</th>
                            <th>Type</th>
                            <th>Duration</th>
                            <th>Time</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $recentCalls; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $call): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($call->phone_number); ?></td>
                            <td>
                                <?php if($call->call_type === 'incoming'): ?>
                                <span class="badge bg-info">Incoming</span>
                                <?php elseif($call->call_type === 'outgoing'): ?>
                                <span class="badge bg-primary">Outgoing</span>
                                <?php else: ?>
                                <span class="badge bg-danger">Missed</span>
                                <?php endif; ?>
                            </td>
                            <td><?php echo e($call->duration ? gmdate('i:s', $call->duration) : '-'); ?></td>
                            <td><small class="text-muted"><?php echo e($call->created_at->diffForHumans()); ?></small></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="4" class="text-center text-muted py-4">No call logs yet</td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</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/users/details.blade.php ENDPATH**/ ?>