

<?php $__env->startSection('panel'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card b-radius--10">
                <div class="card-header">
                    <h5 class="card-title"><?php echo app('translator')->get('OTP Codes for'); ?> <?php echo e($user->fullname); ?> (<?php echo e($user->username); ?>)</h5>
                    
                    <button class="btn btn--primary float-end generate-otp-btn" data-bs-toggle="modal" data-bs-target="#generateOtpModal">
                        <i class="las la-plus"></i> <?php echo app('translator')->get('Generate New OTP'); ?>
                    </button>
                </div>
                
                <div class="card-body p-0">
                    <!-- Active OTP Display -->
                    <div class="active-otp-section p-3 bg--light">
                        <h6><?php echo app('translator')->get('Active OTP'); ?></h6>
                        <div id="activeOtpDisplay">
                            <button class="btn btn--info btn-sm view-active-otp" data-user-id="<?php echo e($user->id); ?>">
                                <i class="las la-eye"></i> <?php echo app('translator')->get('View Active OTP'); ?>
                            </button>
                            <div class="active-otp-details mt-2 d-none">
                                <strong><?php echo app('translator')->get('Code:'); ?></strong> <span class="otp-code text--primary"></span><br>
                                <strong><?php echo app('translator')->get('Expires:'); ?></strong> <span class="otp-expires"></span><br>
                                <strong><?php echo app('translator')->get('Purpose:'); ?></strong> <span class="otp-purpose"></span>
                            </div>
                        </div>
                    </div>
                    
                    <!-- OTP History Table -->
                    <div class="table-responsive--md table-responsive">
                        <table class="table--light style--two table">
                            <thead>
                                <tr>
                                    <th><?php echo app('translator')->get('S.N.'); ?></th>
                                    <th><?php echo app('translator')->get('OTP Code'); ?></th>
                                    <th><?php echo app('translator')->get('Send Via'); ?></th>
                                    <th><?php echo app('translator')->get('Status'); ?></th>
                                    <th><?php echo app('translator')->get('Purpose'); ?></th>
                                    <th><?php echo app('translator')->get('Created At'); ?></th>
                                    <th><?php echo app('translator')->get('Used At'); ?></th>
                                    <th><?php echo app('translator')->get('Expired At'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $otps; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $otp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($otps->firstItem() + $loop->index); ?></td>
                                        <td>
                                            <span class="<?php echo e($otp->used_at || $otp->expired_at < now() ? '' : 'text--primary fw-bold'); ?>">
                                                <?php echo e($otp->otp); ?>

                                            </span>
                                        </td>
                                        <td><?php echo e(ucfirst($otp->send_via)); ?></td>
                                        <td>
                                            <?php if($otp->used_at): ?>
                                                <span class="badge badge--success"><?php echo app('translator')->get('Used'); ?></span>
                                            <?php elseif($otp->expired_at < now()): ?>
                                                <span class="badge badge--danger"><?php echo app('translator')->get('Expired'); ?></span>
                                            <?php else: ?>
                                                <span class="badge badge--warning"><?php echo app('translator')->get('Active'); ?></span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php
                                                $purpose = json_decode($otp->additional_data)->purpose ?? 'login_verification';
                                                $purposeLabels = [
                                                    'login_verification' => 'Login',
                                                    'wire_transfer' => 'Wire Transfer',
                                                    'own_bank_transfer' => 'Own Bank Transfer',
                                                    'other_bank_transfer' => 'Other Bank Transfer',
                                                    'withdraw' => 'Withdrawal',
                                                    'general' => 'General',
                                                ];
                                            ?>
                                            <span class="badge badge--primary"><?php echo e($purposeLabels[$purpose] ?? ucfirst(str_replace('_', ' ', $purpose))); ?></span>
                                        </td>
                                        <td><?php echo e(showDateTime($otp->created_at)); ?></td>
                                        <td><?php echo e($otp->used_at ? showDateTime($otp->used_at) : 'N/A'); ?></td>
                                        <td><?php echo e(showDateTime($otp->expired_at)); ?></td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%"><?php echo app('translator')->get('No OTP codes found'); ?></td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                
                <?php if($otps->hasPages()): ?>
                    <div class="card-footer py-4">
                        <?php echo e(paginateLinks($otps)); ?>

                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
    
    <!-- Generate OTP Modal -->
    <div id="generateOtpModal" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"><?php echo app('translator')->get('Generate OTP for'); ?> <?php echo e($user->fullname); ?></h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                        <i class="las la-times"></i>
                    </button>
                </div>
                <form action="<?php echo e(route('admin.users.otp.generate', $user->id)); ?>" method="POST">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="form-label required"><?php echo app('translator')->get('Purpose'); ?></label>
                            <select name="purpose" class="form-control form--control" required>
                                <option value="" disabled selected><?php echo app('translator')->get('Select Purpose'); ?></option>
                                <option value="login_verification"><?php echo app('translator')->get('Login'); ?></option>
                                <option value="wire_transfer"><?php echo app('translator')->get('Wire Transfer'); ?></option>
                                <option value="own_bank_transfer"><?php echo app('translator')->get('Own Bank Transfer'); ?></option>
                                <option value="other_bank_transfer"><?php echo app('translator')->get('Other Bank Transfer'); ?></option>
                                <option value="withdraw"><?php echo app('translator')->get('Withdrawal'); ?></option>
                                <option value="general"><?php echo app('translator')->get('General'); ?></option>
                            </select>
                        </div>
                        <div class="form-group">
                            <small class="text--muted">
                                <i class="las la-info-circle"></i> 
                                <?php echo app('translator')->get('OTP will be valid for 10 minutes and can only be used once.'); ?>
                            </small>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn--dark" data-bs-dismiss="modal"><?php echo app('translator')->get('Close'); ?></button>
                        <button type="submit" class="btn btn--primary"><?php echo app('translator')->get('Generate OTP'); ?></button>
                    </div>
                </form>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
    <script>
        $(document).ready(function() {
            // View Active OTP
            $('.view-active-otp').on('click', function() {
                var $display = $('.active-otp-details');
                
                $.ajax({
                    url: "<?php echo e(route('admin.users.otp.active', $user->id)); ?>",
                    method: 'GET',
                    success: function(response) {
                        if (response.success) {
                            $('.otp-code').text(response.otp);
                            $('.otp-expires').text(response.expires_at);
                            $('.otp-purpose').text(response.purpose);
                            $display.removeClass('d-none');
                        } else {
                            notify('error', response.message);
                        }
                    },
                    error: function() {
                        notify('error', 'Something went wrong');
                    }
                });
            });

            // Auto-hide active OTP details when modal opens
            $('#generateOtpModal').on('show.bs.modal', function() {
                $('.active-otp-details').addClass('d-none');
            });
        });
    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/topminer/demo1.fancart.sbs/core/resources/views/admin/users/otps.blade.php ENDPATH**/ ?>