

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

<?php $__env->startSection('content'); ?>
<div class="mb-4">
    <a href="<?php echo e(route('dashboard.clients')); ?>" class="text-decoration-none">
        <i class="bi bi-arrow-left me-2"></i>Back to Clients
    </a>
</div>

<div class="row g-4">
    <!-- Client Info Card -->
    <div class="col-lg-4">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center p-4">
                <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($client->name, 0, 1))); ?>

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

                <?php
                $badgeClass = match($client->subscription_type) {
                'trial' => 'bg-warning',
                'basic' => 'bg-info',
                'premium' => 'bg-danger',
                'enterprise' => 'bg-purple',
                default => 'bg-secondary'
                };
                ?>
                <span class="badge <?php echo e($badgeClass); ?> mb-2"><?php echo e(ucfirst($client->subscription_type)); ?></span>

                <div class="d-flex justify-content-center gap-2 mb-3">
                    <?php if(!$client->is_active): ?>
                    <span class="badge bg-secondary">Inactive</span>
                    <?php elseif($client->isSubscriptionExpired()): ?>
                    <span class="badge bg-danger">Expired</span>
                    <?php elseif($client->isOnTrial()): ?>
                    <span class="badge bg-warning">Trial</span>
                    <?php else: ?>
                    <span class="badge bg-success">Active</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($client->phone ?? '-'); ?></div>
                        </div>
                        <div class="col-6">
                            <div class="text-muted">Slug</div>
                            <div class="fw-medium"><?php echo e($client->slug); ?></div>
                        </div>
                        <div class="col-12 mt-3">
                            <div class="text-muted">Address</div>
                            <div class="fw-medium"><?php echo e($client->address ?? '-'); ?></div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Created</div>
                            <div class="fw-medium"><?php echo e($client->created_at->format('M d, Y')); ?></div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Expires</div>
                            <div class="fw-medium <?php echo e($client->getDaysRemaining() <= 7 ? 'text-danger' : ''); ?>">
                                <?php echo e($client->subscription_ends_at?->format('M d, Y') ?? 'N/A'); ?>

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

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

                        </button>
                    </form>
                </div>
            </div>
        </div>

        <!-- Subscription Card -->
        <div class="card border-0 shadow-sm mt-4">
            <div class="card-header bg-transparent">
                <h6 class="mb-0"><i class="bi bi-credit-card me-2"></i>Subscription</h6>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <div class="d-flex justify-content-between text-muted small mb-1">
                        <span>Days Remaining</span>
                        <span><?php echo e($client->getDaysRemaining()); ?> days</span>
                    </div>
                    <?php
                    $daysPercent = min(100, max(0, ($client->getDaysRemaining() / 30) * 100));
                    ?>
                    <div class="progress" style="height: 8px;">
                        <div class="progress-bar <?php echo e($daysPercent < 25 ? 'bg-danger' : ($daysPercent < 50 ? 'bg-warning' : 'bg-success')); ?>" style="width: <?php echo e($daysPercent); ?>%"></div>
                    </div>
                </div>

                <form method="POST" action="<?php echo e(route('dashboard.clients.extend-subscription', $client->id)); ?>">
                    <?php echo csrf_field(); ?>
                    <div class="input-group input-group-sm">
                        <input type="number" class="form-control" name="days" value="30" min="1" max="365" placeholder="Days">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-calendar-plus me-1"></i>Extend
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- Organization Service Controls -->
        <div class="card border-0 shadow-sm mt-4">
            <div class="card-header bg-transparent">
                <h6 class="mb-0"><i class="bi bi-toggles me-2"></i>Service Controls (Organization Level)</h6>
            </div>
            <div class="card-body">
                <p class="text-muted small mb-3">Toggling these will affect <strong>all users</strong> in this organization.</p>

                
                <div class="d-flex justify-content-between align-items-center mb-3 pb-3 border-bottom">
                    <div>
                        <div class="fw-medium"><i class="bi bi-chat-text me-2"></i>SMS Service</div>
                        <small class="text-muted">Auto-reply SMS for all users</small>
                    </div>
                    <form method="POST" action="<?php echo e(route('dashboard.clients.toggle-service', $client->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="service" value="sms_service_enabled">
                        <button type="submit" class="btn btn-sm btn-<?php echo e($client->sms_service_enabled ? 'success' : 'outline-secondary'); ?>">
                            <i class="bi bi-<?php echo e($client->sms_service_enabled ? 'check-circle' : 'x-circle'); ?> me-1"></i>
                            <?php echo e($client->sms_service_enabled ? 'Enabled' : 'Disabled'); ?>

                        </button>
                    </form>
                </div>

                
                <div class="d-flex justify-content-between align-items-center mb-3 pb-3 border-bottom">
                    <div>
                        <div class="fw-medium"><i class="bi bi-whatsapp me-2"></i>WhatsApp Service</div>
                        <small class="text-muted">WhatsApp auto-reply for all users</small>
                    </div>
                    <form method="POST" action="<?php echo e(route('dashboard.clients.toggle-service', $client->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="service" value="whatsapp_service_enabled">
                        <button type="submit" class="btn btn-sm btn-<?php echo e($client->whatsapp_service_enabled ? 'success' : 'outline-secondary'); ?>">
                            <i class="bi bi-<?php echo e($client->whatsapp_service_enabled ? 'check-circle' : 'x-circle'); ?> me-1"></i>
                            <?php echo e($client->whatsapp_service_enabled ? 'Enabled' : 'Disabled'); ?>

                        </button>
                    </form>
                </div>

                
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <div class="fw-medium"><i class="bi bi-megaphone me-2"></i>Promotions</div>
                        <small class="text-muted">Promotional messages for all users</small>
                    </div>
                    <form method="POST" action="<?php echo e(route('dashboard.clients.toggle-service', $client->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="service" value="promotions_enabled">
                        <button type="submit" class="btn btn-sm btn-<?php echo e($client->promotions_enabled ? 'success' : 'outline-secondary'); ?>">
                            <i class="bi bi-<?php echo e($client->promotions_enabled ? 'check-circle' : 'x-circle'); ?> me-1"></i>
                            <?php echo e($client->promotions_enabled ? 'Enabled' : 'Disabled'); ?>

                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- Stats & Details -->
    <div class="col-lg-8">
        <!-- Stats Cards -->
        <div class="row g-3 mb-4">
            <div class="col-md-3">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <h4 class="text-primary mb-0"><?php echo e($stats['total_users']); ?></h4>
                        <small class="text-muted">Total Users</small>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <h4 class="text-warning mb-0"><?php echo e($stats['pending_users']); ?></h4>
                        <small class="text-muted">Pending</small>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <h4 class="text-success mb-0"><?php echo e($stats['approved_users']); ?></h4>
                        <small class="text-muted">Approved</small>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body text-center">
                        <h4 class="text-info mb-0"><?php echo e($stats['total_admins']); ?></h4>
                        <small class="text-muted">Admins</small>
                    </div>
                </div>
            </div>
        </div>

        <!-- Usage Limits -->
        <div class="card border-0 shadow-sm mb-4">
            <div class="card-header bg-transparent">
                <h6 class="mb-0"><i class="bi bi-speedometer2 me-2"></i>Usage Limits</h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <div class="d-flex justify-content-between text-muted small mb-1">
                                <span>Users</span>
                                <span><?php echo e($stats['total_users']); ?> / <?php echo e($client->max_users); ?></span>
                            </div>
                            <?php $userPercent = $client->max_users > 0 ? ($stats['total_users'] / $client->max_users * 100) : 0 ?>
                            <div class="progress" style="height: 8px;">
                                <div class="progress-bar bg-primary" style="width: <?php echo e(min($userPercent, 100)); ?>%"></div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <div class="d-flex justify-content-between text-muted small mb-1">
                                <span>Client Admins</span>
                                <span><?php echo e($stats['total_admins']); ?> / <?php echo e($client->max_client_admins); ?></span>
                            </div>
                            <?php $adminPercent = $client->max_client_admins > 0 ? ($stats['total_admins'] / $client->max_client_admins * 100) : 0 ?>
                            <div class="progress" style="height: 8px;">
                                <div class="progress-bar bg-info" style="width: <?php echo e(min($adminPercent, 100)); ?>%"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Client Admins -->
        <div class="card border-0 shadow-sm mb-4">
            <div class="card-header bg-transparent d-flex justify-content-between align-items-center">
                <h6 class="mb-0"><i class="bi bi-person-gear me-2"></i>Client Admins</h6>
            </div>
            <div class="table-responsive">
                <table class="table mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th>Name</th>
                            <th>Role</th>
                            <th>Status</th>
                            <th>Last Login</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $client->clientAdmins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $admin): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td>
                                <div><?php echo e($admin->name); ?></div>
                                <small class="text-muted"><?php echo e($admin->email); ?></small>
                            </td>
                            <td>
                                <span class="badge bg-<?php echo e($admin->role === 'owner' ? 'danger' : 'primary'); ?>">
                                    <?php echo e(ucfirst($admin->role)); ?>

                                </span>
                            </td>
                            <td>
                                <?php if($admin->is_active): ?>
                                <span class="badge bg-success">Active</span>
                                <?php else: ?>
                                <span class="badge bg-secondary">Inactive</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <small class="text-muted"><?php echo e($admin->last_login_at?->diffForHumans() ?? 'Never'); ?></small>
                            </td>
                            <td>
                                <a href="<?php echo e(route('dashboard.clients.admin-permissions', [$client->id, $admin->id])); ?>" class="btn btn-sm btn-outline-primary" title="Manage Permissions">
                                    <i class="bi bi-shield-lock me-1"></i>Permissions
                                </a>
                            </td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">No client admins</td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Templates -->
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-transparent d-flex justify-content-between align-items-center">
                <h6 class="mb-0"><i class="bi bi-file-text me-2"></i>Assigned Templates</h6>
                <a href="<?php echo e(route('dashboard.template-assignment')); ?>" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-plus-lg me-1"></i>Assign More
                </a>
            </div>
            <div class="table-responsive">
                <table class="table mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th>Template</th>
                            <th>Type</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $client->templates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $template): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td>
                                <div><?php echo e($template->name); ?></div>
                                <?php if($template->isDerived()): ?>
                                <small class="text-muted">From: <?php echo e($template->createdFrom?->name ?? 'Global'); ?></small>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span class="badge bg-light text-dark"><?php echo e(ucfirst($template->type)); ?></span>
                            </td>
                            <td>
                                <?php if($template->is_active): ?>
                                <span class="badge bg-success">Active</span>
                                <?php else: ?>
                                <span class="badge bg-secondary">Inactive</span>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="3" class="text-center text-muted py-4">No templates assigned</td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('styles'); ?>
<style>
    .bg-purple {
        background-color: #8b5cf6 !important;
    }
</style>
<?php $__env->stopPush(); ?>
<?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\clients\show.blade.php ENDPATH**/ ?>