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

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h4 class="mb-1">Client Organizations</h4>
        <p class="text-muted mb-0">Manage client organizations and their subscriptions</p>
    </div>
    <div>
        <a href="<?php echo e(route('dashboard.clients.create')); ?>" class="btn btn-primary">
            <i class="bi bi-plus-lg me-2"></i>Add Client
        </a>
    </div>
</div>

<!-- Stats Row -->
<div class="row g-3 mb-4">
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h3 class="text-primary mb-0"><?php echo e($stats['total']); ?></h3>
                <small class="text-muted">Total Clients</small>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h3 class="text-success mb-0"><?php echo e($stats['active']); ?></h3>
                <small class="text-muted">Active</small>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h3 class="text-warning mb-0"><?php echo e($stats['trial']); ?></h3>
                <small class="text-muted">On Trial</small>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card border-0 shadow-sm">
            <div class="card-body text-center">
                <h3 class="text-danger mb-0"><?php echo e($stats['expired']); ?></h3>
                <small class="text-muted">Expired</small>
            </div>
        </div>
    </div>
</div>

<!-- Filters -->
<div class="card border-0 shadow-sm mb-4">
    <div class="card-body">
        <form method="GET" action="<?php echo e(route('dashboard.clients')); ?>" class="row g-3">
            <div class="col-md-4">
                <input type="text" class="form-control" name="search" placeholder="Search by name, email, or slug..." value="<?php echo e(request('search')); ?>">
            </div>
            <div class="col-md-2">
                <select class="form-select" name="subscription_type">
                    <option value="">All Plans</option>
                    <option value="trial" <?php echo e(request('subscription_type') === 'trial' ? 'selected' : ''); ?>>Trial</option>
                    <option value="basic" <?php echo e(request('subscription_type') === 'basic' ? 'selected' : ''); ?>>Basic</option>
                    <option value="premium" <?php echo e(request('subscription_type') === 'premium' ? 'selected' : ''); ?>>Premium</option>
                    <option value="enterprise" <?php echo e(request('subscription_type') === 'enterprise' ? 'selected' : ''); ?>>Enterprise</option>
                </select>
            </div>
            <div class="col-md-2">
                <select class="form-select" name="status">
                    <option value="">All Status</option>
                    <option value="active" <?php echo e(request('status') === 'active' ? 'selected' : ''); ?>>Active</option>
                    <option value="inactive" <?php echo e(request('status') === 'inactive' ? 'selected' : ''); ?>>Inactive</option>
                    <option value="expired" <?php echo e(request('status') === 'expired' ? 'selected' : ''); ?>>Expired</option>
                </select>
            </div>
            <div class="col-md-2">
                <button type="submit" class="btn btn-outline-primary w-100">
                    <i class="bi bi-funnel me-1"></i>Filter
                </button>
            </div>
            <?php if(request()->hasAny(['search', 'subscription_type', 'status'])): ?>
            <div class="col-md-2">
                <a href="<?php echo e(route('dashboard.clients')); ?>" class="btn btn-outline-secondary w-100">
                    <i class="bi bi-x-circle me-1"></i>Clear
                </a>
            </div>
            <?php endif; ?>
        </form>
    </div>
</div>

<!-- Clients Table -->
<div class="card border-0 shadow-sm">
    <div class="table-responsive">
        <table class="table table-hover mb-0">
            <thead class="bg-light">
                <tr>
                    <th>Organization</th>
                    <th>Subscription</th>
                    <th>Users / Admins</th>
                    <th>Status</th>
                    <th>Expires</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $client): $__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: 40px; height: 40px;">
                                <?php echo e(strtoupper(substr($client->name, 0, 1))); ?>

                            </div>
                            <div>
                                <div class="fw-medium"><?php echo e($client->name); ?></div>
                                <small class="text-muted"><?php echo e($client->email); ?></small>
                            </div>
                        </div>
                    </td>
                    <td>
                        <?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); ?>"><?php echo e(ucfirst($client->subscription_type)); ?></span>
                    </td>
                    <td>
                        <span class="badge bg-light text-dark">
                            <i class="bi bi-people me-1"></i><?php echo e($client->users_count ?? 0); ?> / <?php echo e($client->max_users); ?>

                        </span>
                        <span class="badge bg-light text-dark">
                            <i class="bi bi-person-gear me-1"></i><?php echo e($client->client_admins_count ?? 0); ?> / <?php echo e($client->max_client_admins); ?>

                        </span>
                    </td>
                    <td>
                        <?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 (<?php echo e($client->getDaysRemaining()); ?>d)</span>
                        <?php else: ?>
                        <span class="badge bg-success">Active</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($client->subscription_ends_at): ?>
                        <small class="<?php echo e($client->getDaysRemaining() <= 7 ? 'text-danger fw-bold' : 'text-muted'); ?>">
                            <?php echo e($client->subscription_ends_at->format('M d, Y')); ?>

                        </small>
                        <?php else: ?>
                        <small class="text-muted">N/A</small>
                        <?php endif; ?>
                    </td>
                    <td>
                        <div class="dropdown">
                            <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
                                Actions
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li>
                                    <a class="dropdown-item" href="<?php echo e(route('dashboard.clients.show', $client->id)); ?>">
                                        <i class="bi bi-eye me-2"></i>View Details
                                    </a>
                                </li>
                                <li>
                                    <a class="dropdown-item" href="<?php echo e(route('dashboard.clients.edit', $client->id)); ?>">
                                        <i class="bi bi-pencil me-2"></i>Edit
                                    </a>
                                </li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li>
                                    <button type="button" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#extendModal<?php echo e($client->id); ?>">
                                        <i class="bi bi-calendar-plus me-2"></i>Extend Subscription
                                    </button>
                                </li>
                                <li>
                                    <form method="POST" action="<?php echo e(route('dashboard.clients.toggle-status', $client->id)); ?>">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="dropdown-item <?php echo e($client->is_active ? 'text-warning' : 'text-success'); ?>">
                                            <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>
                                </li>
                            </ul>
                        </div>
                    </td>
                </tr>

                <!-- Extend Subscription Modal -->
                <div class="modal fade" id="extendModal<?php echo e($client->id); ?>" tabindex="-1">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <form method="POST" action="<?php echo e(route('dashboard.clients.extend-subscription', $client->id)); ?>">
                                <?php echo csrf_field(); ?>
                                <div class="modal-header">
                                    <h5 class="modal-title">Extend Subscription - <?php echo e($client->name); ?></h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                </div>
                                <div class="modal-body">
                                    <div class="mb-3">
                                        <label class="form-label">Days to Add</label>
                                        <input type="number" class="form-control" name="days" value="30" min="1" max="365" required>
                                    </div>
                                    <div class="mb-3">
                                        <label class="form-label">Change Plan (Optional)</label>
                                        <select class="form-select" name="subscription_type">
                                            <option value="">Keep Current (<?php echo e(ucfirst($client->subscription_type)); ?>)</option>
                                            <option value="basic">Basic</option>
                                            <option value="premium">Premium</option>
                                            <option value="enterprise">Enterprise</option>
                                        </select>
                                    </div>
                                    <div class="alert alert-info small mb-0">
                                        Current end date: <?php echo e($client->subscription_ends_at?->format('M d, Y') ?? 'N/A'); ?>

                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-primary">Extend Subscription</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr>
                    <td colspan="6" class="text-center py-5">
                        <div class="text-muted mb-3">
                            <i class="bi bi-building" style="font-size: 3rem;"></i>
                        </div>
                        <p class="mb-2">No clients found</p>
                        <a href="<?php echo e(route('dashboard.clients.create')); ?>" class="btn btn-sm btn-primary">
                            <i class="bi bi-plus-lg me-2"></i>Add First Client
                        </a>
                    </td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>

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

    </div>
    <?php endif; ?>
</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 /home/zwfgftjb/autopromix.byteengine.in/resources/views/dashboard/clients/index.blade.php ENDPATH**/ ?>