<?php if (isset($component)) { $__componentOriginal91fdd17964e43374ae18c674f95cdaa3 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal91fdd17964e43374ae18c674f95cdaa3 = $attributes; } ?>
<?php $component = App\View\Components\AdminLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('admin-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AdminLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <div class="container px-6 mx-auto">
        <div class="flex justify-between items-center my-6">
            <h2 class="text-2xl font-semibold text-gray-700">Users Management</h2>
            <a href="<?php echo e(route('admin.users.create')); ?>" 
               class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2">
                <i class="ri-user-add-line mr-2"></i>Create User
            </a>
        </div>

        
        <?php if (isset($component)) { $__componentOriginal6912374916afbfe53350098c2f0b0678 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal6912374916afbfe53350098c2f0b0678 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.session-status','data' => ['class' => 'mb-4','status' => session('status'),'errors' => $errors]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('session-status'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['class' => 'mb-4','status' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(session('status')),'errors' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($errors)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal6912374916afbfe53350098c2f0b0678)): ?>
<?php $attributes = $__attributesOriginal6912374916afbfe53350098c2f0b0678; ?>
<?php unset($__attributesOriginal6912374916afbfe53350098c2f0b0678); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal6912374916afbfe53350098c2f0b0678)): ?>
<?php $component = $__componentOriginal6912374916afbfe53350098c2f0b0678; ?>
<?php unset($__componentOriginal6912374916afbfe53350098c2f0b0678); ?>
<?php endif; ?>

        
        <div class="mb-6 p-4 bg-white rounded-lg shadow-md">
            <form action="<?php echo e(route('admin.users')); ?>" method="GET" class="grid gap-4 md:grid-cols-4">
                <div>
                    <label class="block mb-2 text-sm font-medium text-gray-700">KYC Status</label>
                    <select name="kyc_status" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
                        <option value="">All Status</option>
                        <option value="approved">Approved</option>
                        <option value="pending">Pending</option>
                        <option value="rejected">Rejected</option>
                        <option value="not_submitted">Not Submitted</option>
                    </select>
                </div>
                <div>
                    <label class="block mb-2 text-sm font-medium text-gray-700">Search</label>
                    <input type="text" name="search" placeholder="Search by name, email or ID..." 
                           class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
                </div>
                <div class="md:col-span-2 flex items-end">
                    <button type="submit" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
                        <i class="ri-filter-3-line mr-2"></i>Apply Filters
                    </button>
                </div>
            </form>
        </div>

        
        <div class="bg-white rounded-lg shadow-md overflow-hidden">
            <div class="overflow-x-auto">
                <table class="w-full whitespace-no-wrap">
                    <thead>
                        <tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase bg-gray-50 border-b">
                            <th class="px-4 py-3">User</th>
                            <th class="px-4 py-3">KYC Status</th>
                            <th class="px-4 py-3">Crypto Balance</th>
                            <th class="px-4 py-3">Register Date</th>
                            <th class="px-4 py-3">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y">
                        <?php $__empty_1 = true; $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr class="text-gray-700">
                                <td class="px-4 py-3">
                                    <div class="flex items-center">
                                        <div class="flex-shrink-0 h-10 w-10">
                                            <div class="h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center">
                                                <span class="text-lg font-medium text-purple-600">
                                                    <?php echo e(strtoupper(substr($user->name, 0, 1))); ?>

                                                </span>
                                            </div>
                                        </div>
                                        <div class="ml-4">
                                            <div class="text-sm font-medium"><?php echo e($user->name); ?></div>
                                            <div class="text-sm text-gray-500"><?php echo e($user->email); ?></div>
                                            <div class="text-xs text-gray-400">ID: <?php echo e($user->uuid); ?></div>
                                        </div>
                                    </div>
                                </td>
                                <td class="px-4 py-3">
                                    <span class="px-2 py-1 text-xs rounded-full 
                                        <?php if($user->kyc_status === 'approved'): ?> bg-green-100 text-green-800
                                        <?php elseif($user->kyc_status === 'pending'): ?> bg-yellow-100 text-yellow-800
                                        <?php elseif($user->kyc_status === 'rejected'): ?> bg-red-100 text-red-800
                                        <?php else: ?> bg-gray-100 text-gray-800 <?php endif; ?>">
                                        <?php echo e(ucfirst($user->kyc_status)); ?>

                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    <div class="text-sm">$<?php echo e(number_format($user->getTotalBalanceUSD(), 2)); ?></div>
                                    <div class="text-xs text-gray-500">
                                        <?php echo e($user->hasCryptoAssets() ? count($user->cryptoAssets->getActiveCryptos()) : 0); ?> Active Assets
                                    </div>
                                </td>
                                <td class="px-4 py-3 text-sm">
                                    <?php echo e($user->created_at->format('M d, Y')); ?>

                                </td>
                                <td class="px-4 py-3">
                                    <div class="flex items-center space-x-2">
                                        
                                        <button type="button" title="View Crypto Assets" 
                                                onclick="window.location.href='<?php echo e(route('admin.users.crypto', $user)); ?>'"
                                                class="p-1 text-blue-600 hover:text-blue-900 rounded-full hover:bg-blue-100">
                                            <i class="ri-coin-line text-lg"></i>
                                        </button>
                                         
        <button type="button" 
                title="Edit Crypto Address"
                onclick="openEditAddressModal('<?php echo e($user->id); ?>')"
                class="p-1 text-indigo-600 hover:text-indigo-900 rounded-full hover:bg-indigo-100">
            <i class="ri-edit-circle-line text-lg"></i>
        </button>
        
         <!-- Add the Impersonate button -->
            <?php if(auth()->user()->is_admin): ?>  <!-- Only allow admins to impersonate -->
            
                <a href="<?php echo e(route('admin.impersonate', $user->id)); ?>" class="btn btn-primary"><i class="ri-user-line text-lg"></i>Login</a>
            <?php endif; ?>
        
        
        
        <button type="button" 
        title="Edit Crypto Fees"
        onclick="openFeeModal('<?php echo e($user->id); ?>')"
        class="p-1 text-green-600 hover:text-green-900 rounded-full hover:bg-green-100">
    <i class="ri-money-dollar-circle-line text-lg"></i>
</button>
                                         
                            <button type="button" title="View Cards" 
                            onclick="window.location.href='<?php echo e(route('admin.users.cards', $user)); ?>'"
                            class="p-1 text-green-600 hover:text-green-900 rounded-full hover:bg-green-100">
                            <i class="ri-bank-card-line text-lg"></i>
                            </button>
                            
    <button type="button" title="View Wallet Phrase" 
            data-modal-target="walletPhraseModal-<?php echo e($user->id); ?>"
            class="p-1 text-indigo-600 hover:text-indigo-900 rounded-full hover:bg-indigo-100">
        <i class="ri-key-2-line text-lg"></i>
    </button>
                              
        <button type="button" title="Manage Profile" 
                onclick="openProfileModal('<?php echo e($user->id); ?>')"
                class="p-1 text-purple-600 hover:text-purple-900 rounded-full hover:bg-purple-100">
            <i class="ri-user-settings-line text-lg"></i>
        </button>


                                        
                                        <button type="button" title="Change Password" 
                                                data-modal-target="changePasswordModal-<?php echo e($user->id); ?>"
                                                class="p-1 text-yellow-600 hover:text-yellow-900 rounded-full hover:bg-yellow-100">
                                            <i class="ri-lock-password-line text-lg"></i>
                                        </button>
                                        
                                        <form action="<?php echo e(route('admin.users.destroy', $user)); ?>" method="POST" 
                                              class="inline" onsubmit="return confirm('Are you sure?');">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="submit" title="Delete User"
                                                    class="p-1 text-red-600 hover:text-red-900 rounded-full hover:bg-red-100">
                                                <i class="ri-delete-bin-line text-lg"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                            
                             <!-- Profile Modal -->
                        <?php echo $__env->make('admin.profile.modals.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                        
                                        <!-- Edit Address Modal -->
<!-- Edit Address Modal -->
<div id="editAddressModal-<?php echo e($user->id); ?>" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50 overflow-y-auto">
    <div class="flex items-center justify-center min-h-screen p-4">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl relative">
            <!-- Fixed Header -->
            <div class="sticky top-0 bg-white border-b z-10 rounded-t-lg">
                <div class="flex justify-between items-center p-6">
                    <h3 class="text-lg font-semibold text-gray-900">Edit Crypto Addresses</h3>
                    <button onclick="document.getElementById('editAddressModal-<?php echo e($user->id); ?>').classList.add('hidden')" 
                            class="text-gray-400 hover:text-gray-500">
                        <i class="ri-close-line text-xl"></i>
                    </button>
                </div>
            </div>

            <form action="<?php echo e(route('admin.users.updateAddresses', $user)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>

                <!-- Scrollable Content -->
                <div class="p-6 max-h-[calc(100vh-250px)] overflow-y-auto">
                    <div class="grid gap-6">
                        <?php $__currentLoopData = \App\Models\CryptoAsset::getSupportedCryptos(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $symbol => $crypto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="space-y-2">
                                <label class="block text-sm font-medium text-gray-700">
                                    <?php echo e($crypto['name']); ?> Address
                                    <?php if(isset($crypto['network'])): ?>
                                        <span class="text-xs text-gray-500">(<?php echo e($crypto['network']); ?>)</span>
                                    <?php endif; ?>
                                </label>
                                <div class="flex gap-2">
                                    <input type="text"
                                           name="addresses[<?php echo e($symbol); ?>]"
                                           value="<?php echo e(optional($user->cryptoAssets)->{$symbol.'_address'}); ?>"
                                           class="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
                                  <!--  <button type="button"
                                            onclick="generateAddress('<?php echo e($symbol); ?>', <?php echo e($user->id); ?>)"
                                            class="px-3 py-2 text-sm text-white bg-indigo-600 rounded-lg hover:bg-indigo-700">
                                        Generate
                                    </button> -->
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>

                <!-- Fixed Footer -->
                <div class="sticky bottom-0 bg-white border-t p-6 rounded-b-lg">
                    <div class="flex justify-end space-x-3">
                        <button type="button" 
                                onclick="document.getElementById('editAddressModal-<?php echo e($user->id); ?>').classList.add('hidden')"
                                class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
                            Cancel
                        </button>
                        <button type="submit"
                                class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700">
                            Save Changes
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
                        
                     
<div id="walletPhraseModal-<?php echo e($user->id); ?>" class="hidden fixed inset-0 bg-black bg-opacity-50 z-40">
    <div class="flex items-center justify-center min-h-screen px-4">
        <div class="bg-white rounded-lg shadow-xl max-w-md w-full">
            <div class="p-6">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-lg font-medium text-gray-900">Wallet Phrase for <?php echo e($user->name); ?></h3>
                    <button type="button" 
                            onclick="document.getElementById('walletPhraseModal-<?php echo e($user->id); ?>').classList.add('hidden')"
                            class="text-gray-400 hover:text-gray-500">
                        <i class="ri-close-line text-xl"></i>
                    </button>
                </div>
                
                <div class="bg-gray-50 rounded-lg p-4 mb-4">
                    <p class="text-sm text-gray-500 mb-2">Wallet Recovery Phrase:</p>
                    <div class="bg-white border border-gray-200 rounded p-3">
                        <p class="text-sm font-medium text-gray-800 break-all"><?php echo e($user->wallet_phrase); ?></p>
                    </div>
                </div>

                <div class="mt-4 flex justify-between">
                    <button type="button" 
                            onclick="document.getElementById('walletPhraseModal-<?php echo e($user->id); ?>').classList.add('hidden')"
                            class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
                        Close
                    </button>
                    <form action="<?php echo e(route('admin.users.delete-wallet-phrase', $user->id)); ?>" method="POST" class="ml-2">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('DELETE'); ?>
                        <button type="submit" class="px-4 py-2 text-sm font-medium text-red-700 bg-red-100 rounded-lg hover:bg-red-200">
                            Delete
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
                    <!-- Edit Fee Modal -->
<div id="editFeeModal-<?php echo e($user->id); ?>" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50 overflow-y-auto">
    <div class="flex items-center justify-center min-h-screen p-4">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl relative">
            <!-- Fixed Header -->
            <div class="sticky top-0 bg-white border-b z-10 rounded-t-lg">
                <div class="flex justify-between items-center p-6">
                    <h3 class="text-lg font-semibold text-gray-900">Edit Crypto Fees</h3>
                    <button onclick="document.getElementById('editFeeModal-<?php echo e($user->id); ?>').classList.add('hidden')" 
                            class="text-gray-400 hover:text-gray-500">
                        <i class="ri-close-line text-xl"></i>
                    </button>
                </div>
            </div>

            <form action="<?php echo e(route('admin.users.updateFees', $user)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>

                <!-- Scrollable Content -->
                <div class="p-6 max-h-[calc(100vh-250px)] overflow-y-auto">
                    <div class="grid gap-6">
                        <?php $__currentLoopData = \App\Models\CryptoAsset::getSupportedCryptos(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $symbol => $crypto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="space-y-2">
                                <label class="block text-sm font-medium text-gray-700">
                                    <?php echo e($crypto['name']); ?> Fee
                                    <?php if(isset($crypto['network'])): ?>
                                        <span class="text-xs text-gray-500">(<?php echo e($crypto['network']); ?>)</span>
                                    <?php endif; ?>
                                </label>
                                <div class="flex gap-2">
                                    <input type="number"
                                           step="0.0001"
                                           min="0"
                                           name="fees[<?php echo e($symbol); ?>]"
                                           value="<?php echo e(optional($user->cryptoAssets)->{$symbol.'_fee'}); ?>"
                                           placeholder="0.0000"
                                           class="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>

                <!-- Fixed Footer -->
                <div class="sticky bottom-0 bg-white border-t p-6 rounded-b-lg">
                    <div class="flex justify-end space-x-3">
                        <button type="button" 
                                onclick="document.getElementById('editFeeModal-<?php echo e($user->id); ?>').classList.add('hidden')"
                                class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
                            Cancel
                        </button>
                        <button type="submit"
                                class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700">
                            Save Changes
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

                            
                            <div id="changePasswordModal-<?php echo e($user->id); ?>" class="hidden fixed inset-0 bg-black bg-opacity-50 z-40">
                                <div class="flex items-center justify-center min-h-screen px-4">
                                    <div class="bg-white rounded-lg shadow-xl max-w-md w-full">
                                        <div class="p-6">
                                            <h3 class="text-lg font-medium text-gray-900 mb-4">Change Password for <?php echo e($user->name); ?></h3>
                                            <form action="<?php echo e(route('admin.users.password.update', $user)); ?>" method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('PUT'); ?>
                                                <div class="mb-4">
                                                    <label class="block text-sm font-medium text-gray-700 mb-2">New Password</label>
                                                    <input type="password" name="password" required
                                                           class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
                                                </div>
                                                <div class="mb-4">
                                                    <label class="block text-sm font-medium text-gray-700 mb-2">Confirm Password</label>
                                                    <input type="password" name="password_confirmation" required
                                                           class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500">
                                                </div>
                                                <div class="flex justify-end space-x-3">
                                                    <button type="button" onclick="document.getElementById('changePasswordModal-<?php echo e($user->id); ?>').classList.add('hidden')"
                                                            class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
                                                        Cancel
                                                    </button>
                                                    <button type="submit"
                                                            class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700">
                                                        Update Password
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="5" class="px-4 py-8 text-center text-gray-500">
                                    No users found
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            
            
            <div class="px-4 py-3 border-t">
                <?php echo e($users->links()); ?>

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

    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const modals = document.querySelectorAll('[data-modal-target]');
            
            modals.forEach(trigger => {
                trigger.addEventListener('click', (e) => {
                    const modal = document.getElementById(trigger.dataset.modalTarget);
                    modal.classList.remove('hidden');
                });
            });
        });
        function openFeeModal(userId) {
    document.getElementById(`editFeeModal-${userId}`).classList.remove('hidden');
}
    function openProfileModal(userId) {
        document.getElementById(`profileModal-${userId}`).classList.remove('hidden');
    }
function openEditAddressModal(userId) {
        document.getElementById(`editAddressModal-${userId}`).classList.remove('hidden');
    }

    function generateAddress(symbol, userId) {
        fetch(`/admin/users/${userId}/generate-address/${symbol}`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
            }
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                document.querySelector(`input[name="addresses[${symbol}]"]`).value = data.address;
            }
        })
        .catch(error => console.error('Error:', error));
    }
    </script>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal91fdd17964e43374ae18c674f95cdaa3)): ?>
<?php $attributes = $__attributesOriginal91fdd17964e43374ae18c674f95cdaa3; ?>
<?php unset($__attributesOriginal91fdd17964e43374ae18c674f95cdaa3); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal91fdd17964e43374ae18c674f95cdaa3)): ?>
<?php $component = $__componentOriginal91fdd17964e43374ae18c674f95cdaa3; ?>
<?php unset($__componentOriginal91fdd17964e43374ae18c674f95cdaa3); ?>
<?php endif; ?><?php /**PATH /home/quantumv/Qfselitevault.com/resources/views/admin/users/index.blade.php ENDPATH**/ ?>