<?php
if (Auth('admin')->User()->dashboard_style == 'light') {
    $text = 'dark';
    $bg = 'light';
} else {
    $text = 'light';
    $bg = 'dark';
}
?>

<?php $__env->startSection('content'); ?>
    <?php echo $__env->make('admin.topmenu', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('admin.sidebar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <div class="main-panel">
        <div class="content ">
            <div class="page-inner">
                <?php if(session('success')): ?>
                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        <strong><i class="fa fa-check-circle"></i> Success!</strong> <?php echo e(session('success')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                <?php endif; ?>

                <?php if(session('error')): ?>
                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong><i class="fa fa-times-circle"></i> Error!</strong> <?php echo e(session('error')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                <?php endif; ?>

                <?php if(session('message')): ?>
                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong><i class="fa fa-exclamation-triangle"></i> Alert!</strong> <?php echo e(session('message')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                <?php endif; ?>

                <?php if(session('info')): ?>
                    <div class="alert alert-info alert-dismissible fade show" role="alert">
                        <strong><i class="fa fa-info-circle"></i> Info!</strong> <?php echo e(session('info')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                <?php endif; ?>

                <?php if(session('warning')): ?>
                    <div class="alert alert-warning alert-dismissible fade show" role="alert">
                        <strong><i class="fa fa-exclamation-circle"></i> Warning!</strong> <?php echo e(session('warning')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                <?php endif; ?>

                <?php if($errors->any()): ?>
                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong><i class="fa fa-exclamation-triangle"></i> Validation Errors!</strong>
                        <ul class="mb-0 mt-2">
                            <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <li><?php echo e($error); ?></li>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </ul>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                <?php endif; ?>
                <!-- Beginning of  Dashboard Stats  -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="p-3 card ">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-12 ">

                                        <img alt=""
                                            src="<?php echo e(asset('storage/app/public/photos/' . $user->profile_photo_path)); ?>"
                                            width="60" height="60" style='border-radius: 50%;'>
                                        <h1 class=" pl-2 d-inline text-primary"><?php echo e($user->name); ?> <?php echo e($user->middlename); ?>

                                            <?php echo e($user->lastname); ?></h1><span></span>
                                        <div class="d-inline">
                                            <div class="float-right btn-group">
                                                <a class="btn btn-primary btn-sm" href="<?php echo e(route('manageusers')); ?>"> <i
                                                        class="fa fa-arrow-left"></i> back</a> &nbsp;
                                                <button type="button" class="btn btn-secondary dropdown-toggle btn-sm"
                                                    data-toggle="dropdown" data-display="static" aria-haspopup="true"
                                                    aria-expanded="false">
                                                    Actions
                                                </button>
                                                <div class="dropdown-menu dropdown-menu-lg-right">

                                                    
                                                    
                                                    <?php if($user->email_verified_at): ?>
                                                    <?php else: ?>
                                                        <a href="<?php echo e(url('admin/dashboard/email-verify')); ?>/<?php echo e($user->id); ?>"
                                                            class="dropdown-item">Verify Email</a>
                                                    <?php endif; ?>
                                                    
                                                    
                                                    <a href="#" data-toggle="modal" data-target="#topupModal"
                                                        class="dropdown-item">Fund/Debit Account</a>
                                                    <a href="#" data-toggle="modal" data-target="#bulkTransactionModal"
                                                        class="dropdown-item">Generate Bulk Transactions</a>

                                                    <a href="#" data-toggle="modal" data-target="#accountLimitsModal"
                                                        class="dropdown-item">Manage Account Limits</a>
                                                    <a href="#" data-toggle="modal" data-target="#transferCodesModal"
                                                        class="dropdown-item">Manage Transfer Codes</a>
                                                    <a href="#" data-toggle="modal" data-target="#accountStatusModal"
                                                        class="dropdown-item">Change Account Status</a>
                                                    
                                                    <?php if(in_array($user->account_status ?? '', ['blocked', 'permanently_banned'])): ?>
                                                        <a href="#" data-toggle="modal" data-target="#unblockUserModal"
                                                            class="dropdown-item text-success">
                                                            <i class="fa fa-check-circle"></i> Unblock Account
                                                        </a>
                                                    <?php else: ?>
                                                        <a href="#" data-toggle="modal" data-target="#blockUserModal"
                                                            class="dropdown-item text-danger">
                                                            <i class="fa fa-ban"></i> Block/Ban Account
                                                        </a>
                                                    <?php endif; ?>

                                                    <?php if($card && $card->status == 'active'): ?>
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(route('admin.cards.view', $card->id)); ?>">Manage Card</a>
                                                    <?php elseif($card && $card->status == 'pending'): ?>
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(route('admin.cards.pending')); ?>">Review Card Application</a>
                                                    <?php endif; ?>
                                                    <?php if($card && $card->status == 'active'): ?>
                                                        <a href="<?php echo e(route('admin.cards.view', $card->id)); ?>"
                                                        class="dropdown-item">Card Details</a>
                                                    <?php endif; ?>
                                                    <a href="#" data-toggle="modal" data-target="#TradingModal"
                                                        class="dropdown-item">Change Profile Pics</a>
                                                    <a href="#" data-toggle="modal" data-target="#resetpswdModal"
                                                        class="dropdown-item">Reset Password</a>
                                                    <?php if($user->allowtransfer == 1): ?>
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(url('admin/dashboard/undormant')); ?>/<?php echo e($user->id); ?>">Turn
                                                            Off Domarnt Account</a>
                                                    <?php else: ?>
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(url('admin/dashboard/dormant')); ?>/<?php echo e($user->id); ?>">Turn
                                                            On Dormant Account </a>
                                                    <?php endif; ?>
                                                    <a href="#" data-toggle="modal" data-target="#clearacctModal"
                                                        class="dropdown-item">Clear Account</a>


                                                    <a href="#" data-toggle="modal" data-target="#edituser"
                                                        class="dropdown-item">Edit</a>
                                                    
                                                    <a href="#" data-toggle="modal"
                                                        data-target="#sendmailtooneuserModal" class="dropdown-item">Send
                                                        Email</a>

                                                    <a href="#" data-toggle="modal" data-target="#switchuserModal"
                                                        class="dropdown-item text-success">Login as <?php echo e($user->name); ?></a>
                                                    <a class="dropdown-item"
                                                        href="<?php echo e(route('loginactivity', $user->id)); ?>">Login Activity</a>
                                                    <?php if($user->status == null || $user->status == 'blocked'): ?>
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(url('admin/dashboard/uunblock')); ?>/<?php echo e($user->id); ?>">Unblock</a>
                                                    <?php else: ?>
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(url('admin/dashboard/uublock')); ?>/<?php echo e($user->id); ?>">Block</a>
                                                    <?php endif; ?>
                                                    <a href="#" data-toggle="modal" data-target="#deleteModal"
                                                        class="dropdown-item text-danger">Delete <?php echo e($user->name); ?></a>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="p-3 mt-4 border rounded row ">
                                    <div class="col-12 d-flex justify-content-between align-items-center mb-2">
                                        <h6 class="mb-0"><i class="fa fa-wallet"></i> Account Balances</h6>
                                        <button type="button" class="btn btn-sm btn-outline-primary" onclick="toggleBalanceEdit()">
                                            <i class="fa fa-edit" id="balanceEditIcon"></i> <span id="balanceEditText">Edit Balances</span>
                                        </button>
                                    </div>
                                    
                                    
                                    <div id="balanceDisplay" class="col-12">
                                        <div class="row">
                                            <div class="col-md-3">
                                                <h5 class="text-bold">Account Balance</h5>
                                                <p><?php echo e($user->currency); ?><?php echo e(number_format($user->account_bal, 2)); ?></p>
                                            </div>
                                            <div class="col-md-3">
                                                <h5>Bitcoin (BTC)</h5>
                                                <p><?php echo e(number_format($cryptoAccount->btc ?? 0, 8)); ?> BTC</p>
                                            </div>
                                            <div class="col-md-3">
                                                <h5>Ethereum (ETH)</h5>
                                                <p><?php echo e(number_format($cryptoAccount->eth ?? 0, 8)); ?> ETH</p>
                                            </div>
                                            <div class="col-md-3">
                                                <h5>USDT</h5>
                                                <p><?php echo e(number_format($cryptoAccount->usdt ?? 0, 2)); ?> USDT</p>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    
                                    <div id="balanceEdit" class="col-12" style="display: none;">
                                        <form method="post" action="<?php echo e(route('updateUserBalances', $user->id)); ?>">
                                            <?php echo csrf_field(); ?>
                                            <div class="row">
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label class="font-weight-bold">Account Balance (<?php echo e($user->currency); ?>)</label>
                                                        <input type="number" step="0.01" class="form-control" name="account_bal" value="<?php echo e($user->account_bal); ?>">
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label class="font-weight-bold">Bitcoin (BTC)</label>
                                                        <input type="number" step="0.00000001" class="form-control" name="btc" value="<?php echo e($cryptoAccount->btc ?? 0); ?>">
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label class="font-weight-bold">Ethereum (ETH)</label>
                                                        <input type="number" step="0.00000001" class="form-control" name="eth" value="<?php echo e($cryptoAccount->eth ?? 0); ?>">
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label class="font-weight-bold">USDT</label>
                                                        <input type="number" step="0.01" class="form-control" name="usdt" value="<?php echo e($cryptoAccount->usdt ?? 0); ?>">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="d-flex gap-2">
                                                <button type="submit" class="btn btn-primary btn-sm mr-2">
                                                    <i class="fa fa-save"></i> Save Balances
                                                </button>
                                                <button type="button" class="btn btn-secondary btn-sm" onclick="toggleBalanceEdit()">
                                                    Cancel
                                                </button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                <div class="p-3 mt-2 border rounded row ">
                                    <div class="col-md-3">
                                        <h5>Account Limit</h5>
                                        <p><?php echo e($user->currency); ?><?php echo e(number_format($user->limit)); ?> </p>
                                    </div>

                                    <div class="col-md-3">
                                        <h5>Account Status</h5>
                                        <?php
                                            $statusBadges = [
                                                'active' => 'success',
                                                'dormant' => 'warning',
                                                'daily_limit_exceeded' => 'danger',
                                                'weekly_limit_exceeded' => 'danger',
                                                'monthly_limit_exceeded' => 'danger',
                                                'transaction_declined' => 'danger',
                                            ];
                                            $badge = $statusBadges[$user->account_status ?? 'active'] ?? 'secondary';
                                        ?>
                                        <span class="badge badge-<?php echo e($badge); ?>"><?php echo e(ucwords(str_replace('_', ' ', $user->account_status ?? 'active'))); ?></span>
                                    </div>
                                    <div class="col-md-3">
                                        <h5>Transfer Limits</h5>
                                        <?php if($user->daily_limit_enabled || $user->weekly_limit_enabled || $user->monthly_limit_enabled): ?>
                                            <a href="#" data-toggle="modal" data-target="#accountLimitsModal" class="btn btn-sm btn-info">View Limits</a>
                                        <?php else: ?>
                                            <p>No Limits Set</p>
                                        <?php endif; ?>
                                    </div>
                                </div>
                                
                                <?php if($user->daily_limit_enabled || $user->weekly_limit_enabled || $user->monthly_limit_enabled): ?>
                                <div class="p-3 mt-3 border rounded row" style="background: #f8f9fa;">
                                    <?php if($user->daily_limit_enabled): ?>
                                        <div class="col-md-4">
                                            <h6><i class="fa fa-calendar"></i> Daily Limit</h6>
                                            <p class="mb-0"><strong><?php echo e($user->currency); ?><?php echo e(number_format($user->daily_limit, 2)); ?></strong></p>
                                        </div>
                                    <?php endif; ?>
                                    <?php if($user->weekly_limit_enabled): ?>
                                        <div class="col-md-4">
                                            <h6><i class="fa fa-calendar-week"></i> Weekly Limit</h6>
                                            <p class="mb-0"><strong><?php echo e($user->currency); ?><?php echo e(number_format($user->weekly_limit, 2)); ?></strong></p>
                                        </div>
                                    <?php endif; ?>
                                    <?php if($user->monthly_limit_enabled): ?>
                                        <div class="col-md-4">
                                            <h6><i class="fa fa-calendar-alt"></i> Monthly Limit</h6>
                                            <p class="mb-0"><strong><?php echo e($user->currency); ?><?php echo e(number_format($user->monthly_limit, 2)); ?></strong></p>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <?php endif; ?>

                                
                                <div class="p-3 mt-3 border rounded">
                                    <div class="row align-items-center">
                                        <div class="col-md-8">
                                            <h5 class="mb-0">
                                                <i class="fa fa-shield-alt"></i> Transfer Code Settings
                                            </h5>
                                        </div>
                                        <div class="col-md-4 text-right">
                                            <button class="btn btn-sm btn-info" 
                                                    data-toggle="modal" 
                                                    data-target="#transferCodesModal">
                                                <i class="fa fa-cog"></i> Manage Codes
                                            </button>
                                        </div>
                                    </div>
                                    <hr>
                                    <div class="row">
                                        <div class="col-md-3">
                                            <h6><?php echo e($settings->code1 ?? 'Code 1'); ?></h6>
                                            <?php if($user->code1_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->code1_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->code1status == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="col-md-3">
                                            <h6><?php echo e($settings->code2 ?? 'Code 2'); ?></h6>
                                            <?php if($user->code2_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->code2_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->code2status == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="col-md-3">
                                            <h6><?php echo e($settings->code3 ?? 'Code 3'); ?></h6>
                                            <?php if($user->code3_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->code3_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->code3status == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="col-md-3">
                                            <h6>OTP Verification</h6>
                                            <?php if($user->otp_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->otp_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->otp == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="p-3 mt-4 border rounded row "></div>
                                    <div class="row">
                                        <div class="col-md-3">
                                            <h6><?php echo e($settings->code1 ?? 'Code 1'); ?></h6>
                                            <?php if($user->code1_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->code1_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->code1status == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="col-md-3">
                                            <h6><?php echo e($settings->code2 ?? 'Code 2'); ?></h6>
                                            <?php if($user->code2_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->code2_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->code2status == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="col-md-3">
                                            <h6><?php echo e($settings->code3 ?? 'Code 3'); ?></h6>
                                            <?php if($user->code3_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->code3_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->code3status == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="col-md-3">
                                            <h6>OTP Verification</h6>
                                            <?php if($user->otp_enabled === 1): ?>
                                                <span class="badge badge-success" style="background-color: #2d8659;">
                                                    <i class="fa fa-check"></i> User: Enabled
                                                </span>
                                            <?php elseif($user->otp_enabled === 0): ?>
                                                <span class="badge badge-secondary">
                                                    <i class="fa fa-times"></i> User: Disabled
                                                </span>
                                            <?php else: ?>
                                                <span class="badge badge-warning" style="background-color: #e0a84e;">
                                                    <i class="fa fa-globe"></i> Global (<?php echo e($settings->otp == '1' ? 'On' : 'Off'); ?>)
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                                
                                
                                <?php if(in_array($user->account_status ?? '', ['blocked', 'permanently_banned'])): ?>
                                <div class="p-3 mt-4 border rounded" style="border-color: #dc3545 !important; border-width: 2px !important;">
                                    <div class="d-flex justify-content-between align-items-start mb-3">
                                        <h5 class="text-danger mb-0">
                                            <i class="fa fa-exclamation-triangle"></i> Account Blocked
                                        </h5>
                                        <span class="badge <?php echo e($user->account_status == 'permanently_banned' ? 'badge-danger' : 'badge-warning'); ?> badge-lg" style="font-size: 14px;">
                                            <?php echo e($user->account_status == 'permanently_banned' ? 'PERMANENTLY BANNED' : 'TEMPORARILY BLOCKED'); ?>

                                        </span>
                                    </div>
                                    
                                    <?php if($user->block_reason): ?>
                                    <div class="alert alert-danger">
                                        <strong><i class="fa fa-info-circle"></i> Block Reason:</strong><br>
                                        <?php echo e($user->block_reason); ?>

                                    </div>
                                    <?php endif; ?>
                                    
                                    <div class="row">
                                        <div class="col-md-6">
                                            <p class="mb-2">
                                                <strong>Blocked On:</strong><br>
                                                <?php if($user->blocked_at): ?>
                                                    <?php echo e(\Carbon\Carbon::parse($user->blocked_at)->format('M d, Y \a\t h:i A')); ?>

                                                <?php else: ?>
                                                    N/A
                                                <?php endif; ?>
                                            </p>
                                            <p class="mb-2">
                                                <strong>Blocked By:</strong><br>
                                                <?php if($user->blockedByAdmin): ?>
                                                    <?php echo e($user->blockedByAdmin->firstName); ?> <?php echo e($user->blockedByAdmin->lastName); ?>

                                                <?php else: ?>
                                                    System
                                                <?php endif; ?>
                                            </p>
                                        </div>
                                        <div class="col-md-6">
                                            <?php if($user->unblock_at && $user->account_status == 'blocked'): ?>
                                            <p class="mb-2">
                                                <strong>Scheduled Auto-Unblock:</strong><br>
                                                <span class="text-warning">
                                                    <i class="fa fa-clock"></i> <?php echo e(\Carbon\Carbon::parse($user->unblock_at)->format('M d, Y \a\t h:i A')); ?>

                                                </span>
                                                <br>
                                                <small class="text-muted">
                                                    (<?php echo e(\Carbon\Carbon::parse($user->unblock_at)->diffForHumans()); ?>)
                                                </small>
                                            </p>
                                            <?php elseif($user->account_status == 'permanently_banned'): ?>
                                            <div class="alert alert-danger mb-2">
                                                <i class="fa fa-lock"></i> <strong>Permanent Ban</strong><br>
                                                <small>User cannot access account until manually unblocked</small>
                                            </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    
                                    <div class="mt-3">
                                        <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#unblockUserModal">
                                            <i class="fa fa-check-circle"></i> Unblock Account Now
                                        </button>
                                        <?php if($user->blockHistory && $user->blockHistory->count() > 1): ?>
                                        <button type="button" class="btn btn-info btn-sm ml-2" onclick="alert('Feature coming soon: View complete block history')">
                                            <i class="fa fa-history"></i> View Block History (<?php echo e($user->blockHistory->count()); ?>)
                                        </button>
                                        <?php endif; ?>
                                    </div>
                                </div>
                                <?php endif; ?>
                                
                                <div class="p-3 mt-4 border rounded row ">


                                    
                                    <div class="col-md-3">
                                        <h5>Loans</h5>
                                        
                                        <?php if($user->plan != null): ?>
                                            <a class="btn btn-sm btn-primary d-inline"
                                                href="<?php echo e(route('user.plans', $user->id)); ?>">Veiw loans</a>
                                        <?php else: ?>
                                            <p>No Loan</p>
                                        <?php endif; ?>

                                    </div>
                                    <div class="col-md-3">
                                        <h5>KYC</h5>
                                        <?php if($user->account_verify == 'Not Verified' || $user->account_verify == null): ?>
                                            <span class="badge badge-danger">Not Verified Yet</span>
                                        <?php else: ?>
                                            <span class="badge badge-success">Verified</span>
                                        <?php endif; ?>
                                    </div>
                                    
                                </div>
                                <div class="mt-3 row ">
                                    <div class="col-md-12">
                                        <h5>USER INFORMATION</h5>
                                    </div>
                                </div>
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Fullname</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->name); ?> <?php echo e($user->middlename); ?> <?php echo e($user->lastname); ?></h5>
                                    </div>
                                </div>
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Email Address</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->email); ?></h5>
                                    </div>
                                </div>
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Mobile Number</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->phone); ?></h5>
                                    </div>
                                </div>


                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Account Number</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->usernumber); ?></h5>
                                    </div>
                                </div>
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>4 Digit Transaction Pin</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->pin); ?></h5>
                                    </div>
                                </div>

                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5><?php echo e($settings->code1); ?> Code</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->code1); ?></h5>
                                    </div>
                                </div>

                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5><?php echo e($settings->code2); ?> Code</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->code2); ?></h5>
                                    </div>
                                </div>

                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5><?php echo e($settings->code3); ?> Code</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->code3); ?></h5>
                                    </div>
                                </div>
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Date of birth</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->dob); ?></h5>
                                    </div>
                                </div>
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Nationality</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e($user->country); ?></h5>
                                    </div>
                                </div>
                                
                                <div class="p-3 border row ">
                                    <div class="col-md-4 border-right">
                                        <h5>Registered</h5>
                                    </div>
                                    <div class="col-md-8">
                                        <h5><?php echo e(\Carbon\Carbon::parse($user->created_at)->toDayDateTimeString()); ?></h5>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

        
        <div class="mb-5 row mt-4">
            <div class="col card p-3 shadow">
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="font-weight-bold mb-0">
                        <i class="fa fa-exchange-alt mr-2" style="color: #2d8659;"></i>Transaction History
                        <span class="badge badge-primary ml-2"><?php echo e($withdrawals->count()); ?></span>
                    </h4>
                </div>

                <?php if($withdrawals->count() > 0): ?>
                <div class="bs-example widget-shadow table-responsive" data-example-id="user-txn-table">
                    <table id="UserTxnTable" class="table table-hover table-striped">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>TXN ID</th>
                                <th>Amount</th>
                                <th>Description</th>
                                <th>Type</th>
                                <th>Payment Method</th>
                                <th>Beneficiary</th>
                                <th>Status</th>
                                <th>Date</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $withdrawals; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $txn): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($txn->id); ?></td>
                                    <td><small class="text-muted"><?php echo e($txn->txn_id); ?></small></td>
                                    <td><?php echo e($user->currency); ?><?php echo e(number_format($txn->amount, 2)); ?></td>
                                    <td><?php echo e(\Illuminate\Support\Str::limit($txn->Description, 30)); ?></td>
                                    <td>
                                        <?php if($txn->type === 'Credit'): ?>
                                            <span class="badge badge-success">Credit</span>
                                        <?php else: ?>
                                            <span class="badge badge-danger">Debit</span>
                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo e($txn->payment_mode); ?></td>
                                    <td><?php echo e($txn->accountname); ?></td>
                                    <td>
                                        <?php if($txn->status == 'Processed'): ?>
                                            <span class="badge badge-success"><?php echo e($txn->status); ?></span>
                                        <?php elseif(in_array($txn->status, ['On-hold', 'Pending', 'Under Review'])): ?>
                                            <span class="badge badge-warning"><?php echo e($txn->status); ?></span>
                                        <?php elseif(in_array($txn->status, ['Reversed', 'Refunded'])): ?>
                                            <span class="badge badge-info"><?php echo e($txn->status); ?></span>
                                        <?php elseif($txn->status == 'Scheduled'): ?>
                                            <span class="badge badge-primary"><?php echo e($txn->status); ?></span>
                                        <?php elseif($txn->status == 'Cancelled'): ?>
                                            <span class="badge badge-secondary"><?php echo e($txn->status); ?></span>
                                        <?php elseif(in_array($txn->status, ['Expired', 'Frozen'])): ?>
                                            <span class="badge badge-dark"><?php echo e($txn->status); ?></span>
                                        <?php else: ?>
                                            <span class="badge badge-danger"><?php echo e($txn->status); ?></span>
                                        <?php endif; ?>
                                    </td>
                                    <td><small><?php echo e(\Carbon\Carbon::parse($txn->created_at)->toDayDateTimeString()); ?></small></td>
                                    <td class="text-nowrap">
                                        <button type="button" class="btn btn-success btn-sm mb-1" title="Quick Process"
                                                onclick="openQuickProcessModal(<?php echo e($txn->id); ?>, '<?php echo e($txn->txn_id); ?>', '<?php echo e($user->currency); ?><?php echo e(number_format($txn->amount, 2)); ?>', '<?php echo e($txn->accountname); ?>')">
                                            <i class="fa fa-cog"></i>
                                        </button>
                                        <a href="<?php echo e(route('processwithdraw', $txn->id)); ?>" class="btn btn-info btn-sm mb-1" title="View Details">
                                            <i class="fa fa-eye"></i>
                                        </a>
                                        <button type="button" class="btn btn-primary btn-sm mb-1" title="Edit Transaction"
                                                onclick="openUserTxnEditModal(<?php echo e(json_encode($txn)); ?>)">
                                            <i class="fa fa-edit"></i>
                                        </button>
                                        
                                        <button type="button" class="btn btn-danger btn-sm mb-1" title="Delete Transaction"
                                                onclick="confirmDeleteUserTxn(<?php echo e($txn->id); ?>, '<?php echo e($txn->txn_id); ?>')">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
                <?php else: ?>
                <div class="text-center py-5">
                    <i class="fa fa-inbox fa-3x text-muted mb-3"></i>
                    <p class="text-muted">No transactions found for this user.</p>
                </div>
                <?php endif; ?>
            </div>
        </div>
            </div>
        </div>
        </div>

        
        <div class="modal fade" id="userTxnEditModal" tabindex="-1" role="dialog">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <form id="userTxnEditForm" method="POST">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>
                        <input type="hidden" name="redirect_to" value="<?php echo e(route('viewuser', $user->id)); ?>">
                        <div class="modal-header bg-primary text-white">
                            <h5 class="modal-title"><i class="fa fa-edit mr-2"></i>Edit Transaction</h5>
                            <button type="button" class="close text-white" data-dismiss="modal">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <input type="hidden" id="utxn_edit_id" name="withdrawal_id">

                            
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label class="font-weight-bold">Transaction ID</label>
                                    <input type="text" class="form-control" id="utxn_edit_txn_id" name="txn_id" readonly>
                                </div>
                                <div class="col-md-6">
                                    <label class="font-weight-bold">Account Holder</label>
                                    <input type="text" class="form-control" value="<?php echo e($user->name); ?>" readonly>
                                </div>
                            </div>

                            
                            <div class="row mb-3">
                                <div class="col-md-4">
                                    <label class="font-weight-bold">Amount <span class="text-danger">*</span></label>
                                    <input type="number" step="0.01" class="form-control" id="utxn_edit_amount" name="amount" required>
                                </div>
                                <div class="col-md-4">
                                    <label class="font-weight-bold">Type <span class="text-danger">*</span></label>
                                    <select class="form-control" id="utxn_edit_type" name="type" required onchange="utxnToggleSenderFields()">
                                        <option value="Credit">Credit</option>
                                        <option value="Debit">Debit</option>
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <label class="font-weight-bold">Status <span class="text-danger">*</span></label>
                                    <select class="form-control" id="utxn_edit_status" name="status" required>
                                        <option value="Pending">Pending</option>
                                        <option value="Processed">Processed</option>
                                        <option value="On-hold">On-hold</option>
                                        <option value="Rejected">Rejected</option>
                                        <option value="Failed">Failed</option>
                                        <option value="Cancelled">Cancelled</option>
                                        <option value="Reversed">Reversed</option>
                                        <option value="Refunded">Refunded</option>
                                        <option value="Scheduled">Scheduled</option>
                                        <option value="Expired">Expired</option>
                                        <option value="Under Review">Under Review</option>
                                        <option value="Frozen">Frozen</option>
                                    </select>
                                </div>
                            </div>

                            
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label class="font-weight-bold">Payment Method <span class="text-danger">*</span></label>
                                    <select class="form-control" id="utxn_edit_payment_mode" name="payment_mode" required onchange="utxnTogglePaymentFields()">
                                        <option value="Wire Transfer">Wire Transfer</option>
                                        <option value="Internal Transfer">Internal Transfer</option>
                                        <option value="Domestic Transfer">Domestic Transfer</option>
                                        <option value="Local transfer">Local Transfer</option>
                                        <option value="Western Union">Western Union</option>
                                        <option value="Bitcoin">Bitcoin</option>
                                        <option value="Ethereum">Ethereum</option>
                                        <option value="USDT">USDT</option>
                                        <option value="Cryptocurrency">Cryptocurrency</option>
                                        <option value="PayPal">PayPal</option>
                                        <option value="Skrill">Skrill</option>
                                        <option value="Payoneer">Payoneer</option>
                                        <option value="TransferWise">TransferWise</option>
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label class="font-weight-bold">Transaction Date</label>
                                    <input type="datetime-local" class="form-control" id="utxn_edit_date" name="date">
                                </div>
                            </div>

                            
                            <div class="row mb-3">
                                <div class="col-12">
                                    <label class="font-weight-bold">Description</label>
                                    <textarea class="form-control" id="utxn_edit_description" name="Description" rows="2"></textarea>
                                </div>
                            </div>

                            
                            <div id="utxnSenderFieldsSection" class="border-top pt-3 mb-3" style="display: none;">
                                <h6 class="font-weight-bold mb-3" id="utxnSenderHeaderText">Sender Information</h6>
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label id="utxnSenderNameLabel">Sender Name</label>
                                        <input type="text" class="form-control" id="utxn_edit_sender_name" name="sender_name">
                                    </div>
                                    <div class="col-md-6">
                                        <label id="utxnSenderBankLabel">Sender Bank</label>
                                        <input type="text" class="form-control" id="utxn_edit_sender_bank" name="sender_bank">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label id="utxnSenderAccountLabel">Sender Account Number</label>
                                        <input type="text" class="form-control" id="utxn_edit_sender_account_number" name="sender_account_number">
                                    </div>
                                    <div class="col-md-6">
                                        <label>Reference Number</label>
                                        <input type="text" class="form-control" id="utxn_edit_reference_number" name="reference_number">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-12">
                                        <label id="utxnSenderAddressLabel">Sender Bank Address</label>
                                        <textarea class="form-control" id="utxn_edit_sender_bank_address" name="sender_bank_address" rows="2"></textarea>
                                    </div>
                                </div>
                            </div>

                            
                            <div class="border-top pt-3 mb-3">
                                <h6 class="font-weight-bold mb-3">Beneficiary Information</h6>
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label class="font-weight-bold">Account Name <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" id="utxn_edit_accountname" name="accountname" required>
                                    </div>
                                    <div class="col-md-6">
                                        <label class="font-weight-bold" id="utxnAccountNumberLabel">Account Number <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" id="utxn_edit_accountnumber" name="accountnumber" required>
                                    </div>
                                </div>

                                <div id="utxnBankTransferFields">
                                    <div class="row mb-3">
                                        <div class="col-md-6">
                                            <label>Bank Name</label>
                                            <input type="text" class="form-control" id="utxn_edit_bankname" name="bankname">
                                        </div>
                                        <div class="col-md-6">
                                            <label>Account Type</label>
                                            <select class="form-control" id="utxn_edit_accounttype" name="Accounttype">
                                                <option value="">Select Account Type</option>
                                                <option value="Checking">Checking</option>
                                                <option value="Savings">Savings</option>
                                                <option value="Business">Business</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="row mb-3">
                                        <div class="col-md-4">
                                            <label>SWIFT Code</label>
                                            <input type="text" class="form-control" id="utxn_edit_swiftcode" name="swiftcode">
                                        </div>
                                        <div class="col-md-4">
                                            <label>IBAN</label>
                                            <input type="text" class="form-control" id="utxn_edit_iban" name="iban">
                                        </div>
                                        <div class="col-md-4">
                                            <label>Routing Number</label>
                                            <input type="text" class="form-control" id="utxn_edit_routingnumber" name="routingnumber">
                                        </div>
                                    </div>
                                </div>

                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label>Country</label>
                                        <input type="text" class="form-control" id="utxn_edit_country" name="country">
                                    </div>
                                    <div class="col-md-6">
                                        <label>City</label>
                                        <input type="text" class="form-control" id="utxn_edit_city" name="city">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label>Zip Code</label>
                                        <input type="text" class="form-control" id="utxn_edit_zipcode" name="zipcode">
                                    </div>
                                    <div class="col-md-6">
                                        <label>Bank Address</label>
                                        <input type="text" class="form-control" id="utxn_edit_bankaddress" name="bankaddress">
                                    </div>
                                </div>
                            </div>

                            
                            <div class="border-top pt-3 mb-3">
                                <h6 class="font-weight-bold mb-3">Additional Information</h6>
                                <div class="row mb-3">
                                    <div class="col-md-6">
                                        <label>Balance After Transaction</label>
                                        <input type="number" step="0.01" class="form-control" id="utxn_edit_bal" name="bal">
                                    </div>
                                    <div class="col-md-6">
                                        <label>Amount to Deduct</label>
                                        <input type="number" step="0.01" class="form-control" id="utxn_edit_to_deduct" name="to_deduct">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-12">
                                        <label>Payment Details</label>
                                        <textarea class="form-control" id="utxn_edit_paydetails" name="paydetails" rows="2"></textarea>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-12">
                                        <label>Admin Note</label>
                                        <textarea class="form-control" id="utxn_edit_admin_note" name="admin_note" rows="2" placeholder="Internal notes (not visible to user)"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="submit" class="btn btn-primary">
                                <i class="fa fa-save mr-1"></i> Save Changes
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        
        <div class="modal fade" id="userTxnProcessModal" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <form method="POST" action="<?php echo e(route('pwithdrawal')); ?>">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="redirect_to" value="<?php echo e(route('viewuser', $user->id)); ?>">
                        <input type="hidden" name="id" id="utxn_process_id">
                        <div class="modal-header bg-success text-white">
                            <h5 class="modal-title"><i class="fa fa-cog mr-2"></i>Quick Process Transaction</h5>
                            <button type="button" class="close text-white" data-dismiss="modal">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="alert alert-light border mb-3">
                                <strong>Transaction:</strong> <span id="utxn_process_txn_id"></span><br>
                                <strong>Amount:</strong> <span id="utxn_process_amount"></span><br>
                                <strong>Beneficiary:</strong> <span id="utxn_process_beneficiary"></span>
                            </div>

                            <div class="form-group">
                                <label class="font-weight-bold">Action <span class="text-danger">*</span></label>
                                <select class="form-control" name="action" id="utxn_process_action" required onchange="utxnToggleEmailFields()">
                                    <option value="">-- Select Action --</option>
                                    <option value="Paid">Paid / Processed</option>
                                    <option value="Reject">Reject</option>
                                    <option value="On-hold">On-hold</option>
                                    <option value="Under-review">Under Review</option>
                                    <option value="Frozen">Frozen</option>
                                    <option value="Scheduled">Scheduled</option>
                                    <option value="Failed">Failed</option>
                                    <option value="Cancelled">Cancelled</option>
                                    <option value="Reversed">Reversed</option>
                                    <option value="Refunded">Refunded</option>
                                    <option value="Expired">Expired</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label class="font-weight-bold">Date</label>
                                <input type="datetime-local" name="date" class="form-control" value=" ">
                            </div>

                            
                            <div id="utxnEmailSection" style="display: none;">
                                <div class="form-group">
                                    <label class="font-weight-bold">Send Notification Email?</label>
                                    <div>
                                        <div class="form-check form-check-inline">
                                            <input class="form-check-input" type="radio" name="emailsend" id="utxn_email_yes" value="true">
                                            <label class="form-check-label" for="utxn_email_yes">Yes</label>
                                        </div>
                                        <div class="form-check form-check-inline">
                                            <input class="form-check-input" type="radio" name="emailsend" id="utxn_email_no" value="false" checked>
                                            <label class="form-check-label" for="utxn_email_no">No</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="font-weight-bold">Subject</label>
                                    <input type="text" class="form-control" name="subject" placeholder="Email subject">
                                </div>
                                <div class="form-group">
                                    <label class="font-weight-bold">Reason / Message</label>
                                    <textarea class="form-control" name="reason" rows="3" placeholder="Reason for this action..."></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="submit" class="btn btn-success">
                                <i class="fa fa-check mr-1"></i> Process
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        
        <form id="deleteUserTxnForm" method="POST" style="display: none;">
            <?php echo csrf_field(); ?>
            <?php echo method_field('DELETE'); ?>
            <input type="hidden" name="redirect_to" value="<?php echo e(route('viewuser', $user->id)); ?>">
        </form>

        
        <script>
            // ---- Edit Modal ----
            function openUserTxnEditModal(txn) {
                document.getElementById('userTxnEditForm').action = "<?php echo e(url('admin/dashboard/withdrawals')); ?>/" + txn.id;
                document.getElementById('utxn_edit_id').value = txn.id;
                document.getElementById('utxn_edit_txn_id').value = txn.txn_id || '';
                document.getElementById('utxn_edit_amount').value = txn.amount || '';
                document.getElementById('utxn_edit_type').value = txn.type || 'Debit';
                document.getElementById('utxn_edit_status').value = txn.status || 'Pending';
                document.getElementById('utxn_edit_payment_mode').value = txn.payment_mode || '';
                document.getElementById('utxn_edit_description').value = txn.Description || '';

                if (txn.created_at) {
                    var d = new Date(txn.created_at);
                    document.getElementById('utxn_edit_date').value = d.toISOString().slice(0, 16);
                }

                // Sender
                document.getElementById('utxn_edit_sender_name').value = txn.sender_name || '';
                document.getElementById('utxn_edit_sender_bank').value = txn.sender_bank || '';
                document.getElementById('utxn_edit_sender_account_number').value = txn.sender_account_number || '';
                document.getElementById('utxn_edit_sender_bank_address').value = txn.sender_bank_address || '';
                document.getElementById('utxn_edit_reference_number').value = txn.reference_number || '';

                // Beneficiary
                document.getElementById('utxn_edit_accountname').value = txn.accountname || '';
                document.getElementById('utxn_edit_accountnumber').value = txn.accountnumber || '';
                document.getElementById('utxn_edit_bankname').value = txn.bankname || '';
                document.getElementById('utxn_edit_accounttype').value = txn.Accounttype || '';
                document.getElementById('utxn_edit_swiftcode').value = txn.swiftcode || '';
                document.getElementById('utxn_edit_iban').value = txn.iban || '';
                document.getElementById('utxn_edit_routingnumber').value = txn.routingnumber || '';

                // Location
                document.getElementById('utxn_edit_country').value = txn.country || '';
                document.getElementById('utxn_edit_city').value = txn.city || '';
                document.getElementById('utxn_edit_zipcode').value = txn.zipcode || '';
                document.getElementById('utxn_edit_bankaddress').value = txn.bankaddress || '';

                // Additional
                document.getElementById('utxn_edit_bal').value = txn.bal || '';
                document.getElementById('utxn_edit_to_deduct').value = txn.to_deduct || '';
                document.getElementById('utxn_edit_paydetails').value = txn.paydetails || '';
                document.getElementById('utxn_edit_admin_note').value = txn.admin_note || '';

                utxnToggleSenderFields();
                utxnTogglePaymentFields();

                $('#userTxnEditModal').modal('show');
            }

            function utxnToggleSenderFields() {
                var type = document.getElementById('utxn_edit_type').value;
                var section = document.getElementById('utxnSenderFieldsSection');
                var header = document.getElementById('utxnSenderHeaderText');
                var nameL = document.getElementById('utxnSenderNameLabel');
                var bankL = document.getElementById('utxnSenderBankLabel');
                var acctL = document.getElementById('utxnSenderAccountLabel');
                var addrL = document.getElementById('utxnSenderAddressLabel');

                section.style.display = 'block';
                if (type === 'Credit') {
                    header.textContent = 'Sender Information';
                    nameL.textContent = 'Sender Name';
                    bankL.textContent = 'Sender Bank';
                    acctL.textContent = 'Sender Account Number';
                    addrL.textContent = 'Sender Bank Address';
                } else {
                    header.textContent = 'Recipient Information';
                    nameL.textContent = 'Recipient Name';
                    bankL.textContent = 'Recipient Bank';
                    acctL.textContent = 'Recipient Account Number';
                    addrL.textContent = 'Recipient Bank Address';
                }
            }

            function utxnTogglePaymentFields() {
                var pm = document.getElementById('utxn_edit_payment_mode').value;
                var bankFields = document.getElementById('utxnBankTransferFields');
                var label = document.getElementById('utxnAccountNumberLabel');

                if (['Wire Transfer', 'Internal Transfer', 'Domestic Transfer', 'Local transfer'].includes(pm)) {
                    bankFields.style.display = 'block';
                    label.innerHTML = 'Account Number <span class="text-danger">*</span>';
                } else if (['Bitcoin', 'Ethereum', 'USDT', 'Cryptocurrency'].includes(pm)) {
                    bankFields.style.display = 'none';
                    label.innerHTML = 'Wallet Address <span class="text-danger">*</span>';
                } else if (['PayPal', 'Skrill', 'Payoneer', 'TransferWise'].includes(pm)) {
                    bankFields.style.display = 'none';
                    label.innerHTML = 'Email Address <span class="text-danger">*</span>';
                } else if (pm === 'Western Union') {
                    bankFields.style.display = 'none';
                    label.innerHTML = 'Recipient Name <span class="text-danger">*</span>';
                } else {
                    bankFields.style.display = 'block';
                    label.innerHTML = 'Account Number <span class="text-danger">*</span>';
                }
            }

            // ---- Quick Process Modal ----
            function openQuickProcessModal(id, txnId, amount, beneficiary) {
                document.getElementById('utxn_process_id').value = id;
                document.getElementById('utxn_process_txn_id').textContent = txnId;
                document.getElementById('utxn_process_amount').textContent = amount;
                document.getElementById('utxn_process_beneficiary').textContent = beneficiary;
                document.getElementById('utxn_process_action').value = '';
                document.getElementById('utxnEmailSection').style.display = 'none';
                $('#userTxnProcessModal').modal('show');
            }

            function utxnToggleEmailFields() {
                var action = document.getElementById('utxn_process_action').value;
                var emailSection = document.getElementById('utxnEmailSection');
                if (['Reject', 'Failed', 'Cancelled', 'Reversed', 'Refunded', 'Expired'].includes(action)) {
                    emailSection.style.display = 'block';
                } else {
                    emailSection.style.display = 'none';
                }
            }

            // ---- Delete ----
            function confirmDeleteUserTxn(id, txnId) {
                if (confirm('Are you sure you want to delete transaction ' + txnId + '?\n\nThis action cannot be undone!')) {
                    var form = document.getElementById('deleteUserTxnForm');
                    form.action = "<?php echo e(url('admin/dashboard/withdrawals')); ?>/" + id;
                    form.submit();
                }
            }

            // ---- DataTable init ----
            $(document).ready(function() {
                if ($.fn.DataTable && !$.fn.DataTable.isDataTable('#UserTxnTable')) {
                    $('#UserTxnTable').DataTable({
                        "order": [[0, "desc"]],
                        "pageLength": 10,
                        "language": {
                            "emptyTable": "No transactions found"
                        }
                    });
                }
            });
        </script>

        
        <script>
            function toggleBalanceEdit() {
                var display = document.getElementById('balanceDisplay');
                var edit = document.getElementById('balanceEdit');
                var text = document.getElementById('balanceEditText');
                if (edit.style.display === 'none') {
                    edit.style.display = 'block';
                    display.style.display = 'none';
                    text.textContent = 'Cancel';
                } else {
                    edit.style.display = 'none';
                    display.style.display = 'block';
                    text.textContent = 'Edit Balances';
                }
            }
        </script>

        <?php echo $__env->make('admin.Users.users_actions', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/elitecha/ccifb.online/resources/views/admin/Users/userdetails.blade.php ENDPATH**/ ?>