
<?php $__env->startSection('title', $user->name); ?>
<?php $__env->startSection('content'); ?>
<div class="page-header" style="display:flex;justify-content:space-between;align-items:flex-start;flex-wrap:wrap;gap:1rem">
    <div><h1><?php echo e($user->name); ?></h1><p><?php echo e($user->email); ?> · {{ $user->username }}</p></div>
    <div class="action-group">
        <a href="<?php echo e(route('admin.users.edit', $user)); ?>" class="md-btn md-btn-filled">Edit User</a>
        <form action="<?php echo e(route('admin.users.toggle-status', $user)); ?>" method="POST"
              onsubmit="return confirm('<?php echo e($user->status === 'active' ? 'Deactivate this user? They will not be able to sign in.' : 'Reactivate this user?'); ?>')">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PATCH'); ?>
            <?php if($user->status === 'active'): ?>
                <button type="submit" class="md-btn md-btn-danger">Deactivate</button>
            <?php else: ?>
                <button type="submit" class="md-btn md-btn-tonal">Activate</button>
            <?php endif; ?>
        </form>
    </div>
</div>

<div class="stat-grid" style="margin-bottom:1.5rem">
    <div class="stat-tile"><div><p class="stat-tile-label">Balance</p><p class="stat-tile-value" id="userCurrentBalance">$<?php echo e(number_format($user->balance, 2)); ?></p></div></div>
    <div class="stat-tile"><div><p class="stat-tile-label">Status</p><p class="stat-tile-value"><?php echo e($user->status === 'active' ? 'Active' : 'Deactivated'); ?></p></div></div>
    <div class="stat-tile"><div><p class="stat-tile-label">Deposits</p><p class="stat-tile-value"><?php echo e($user->deposits->count()); ?></p></div></div>
    <div class="stat-tile"><div><p class="stat-tile-label">Withdrawals</p><p class="stat-tile-value"><?php echo e($user->withdrawals->count()); ?></p></div></div>
</div>

<div class="md-card" style="margin-bottom:1.5rem">
    <div class="md-card-header">Recent Trades</div>
    <div class="table-wrap">
        <table class="md-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Pair</th>
                    <th>Direction</th>
                    <th>Amount</th>
                    <th>Result</th>
                    <th>Net P&amp;L</th>
                    <th>Status</th>
                    <th>Closed</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $user->trades; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td>#<?php echo e($trade->id); ?></td>
                    <td><?php echo e($trade->market?->tradePairLabel() ?? '—'); ?></td>
                    <td><?php echo e(strtoupper($trade->direction)); ?></td>
                    <td>$<?php echo e(number_format($trade->amount, 2)); ?></td>
                    <td>
                        <?php if($trade->outcome === 'won'): ?>
                            <span class="badge badge-success">WIN</span>
                        <?php elseif($trade->outcome === 'lost'): ?>
                            <span class="badge badge-danger">LOSS</span>
                        <?php else: ?>
                            <span class="badge">—</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($trade->net_pnl !== null): ?>
                            <span style="color:<?php echo e((float) $trade->net_pnl >= 0 ? 'var(--md-success)' : 'var(--md-error)'); ?>">
                                <?php echo e((float) $trade->net_pnl >= 0 ? '+' : ''); ?>$<?php echo e(number_format($trade->net_pnl, 2)); ?>

                            </span>
                        <?php else: ?>
                            —
                        <?php endif; ?>
                    </td>
                    <td><?php echo e(ucfirst($trade->status)); ?></td>
                    <td><?php echo e($trade->closed_at?->format('Y-m-d H:i') ?? '—'); ?></td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="8" style="text-align:center;padding:1.5rem">No trades yet</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<div class="md-card" style="margin-bottom:1.5rem">
    <div class="md-card-header" style="display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:0.75rem">
        <span>All Transactions (<?php echo e($transactions->total()); ?>)</span>
    </div>
    <form class="toolbar" method="GET" action="<?php echo e(route('admin.users.show', $user)); ?>" style="padding:0 1rem 1rem;margin:0">
        <select name="type" class="md-select">
            <option value="all">All Types</option>
            <option value="deposit" <?php if(request('type') === 'deposit'): echo 'selected'; endif; ?>>Deposit</option>
            <option value="withdrawal" <?php if(request('type') === 'withdrawal'): echo 'selected'; endif; ?>>Withdrawal</option>
            <option value="transfer" <?php if(request('type') === 'transfer'): echo 'selected'; endif; ?>>Transfer</option>
            <option value="balance_add" <?php if(request('type') === 'balance_add'): echo 'selected'; endif; ?>>Balance Add</option>
            <option value="balance_subtract" <?php if(request('type') === 'balance_subtract'): echo 'selected'; endif; ?>>Balance Subtract</option>
        </select>
        <button type="submit" class="md-btn md-btn-tonal">Filter</button>
        <?php if(request('type') && request('type') !== 'all'): ?>
            <a href="<?php echo e(route('admin.users.show', $user)); ?>" class="md-btn md-btn-tonal">Clear</a>
        <?php endif; ?>
    </form>
    <div class="table-wrap">
        <table class="md-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Type</th>
                    <th>Details</th>
                    <th>Amount</th>
                    <th>Status</th>
                    <th>Date</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td><?php echo e($tx->id); ?></td>
                    <td><?php echo e(str_replace('_', ' ', ucfirst($tx->type))); ?></td>
                    <td style="max-width:320px"><?php echo e($tx->details ?? '—'); ?></td>
                    <td>$<?php echo e(number_format($tx->amount, 2)); ?></td>
                    <td><span class="badge <?php echo e($tx->status->badgeClass()); ?>"><?php echo e($tx->status->label()); ?></span></td>
                    <td><?php echo e($tx->created_at->format('Y-m-d H:i:s')); ?></td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="6" style="text-align:center;padding:1.5rem">No transactions for this client</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
    <?php if($transactions->hasPages()): ?>
    <div style="padding:1rem"><?php echo e($transactions->links()); ?></div>
    <?php endif; ?>
</div>

<div class="md-card balance-adjust-card">
    <div class="md-card-header">Balance Add/Subtract</div>
    <div class="md-card-body balance-adjust-body">
        <div class="balance-adjust-col">
            <form method="POST" action="<?php echo e(route('admin.users.balance.add', $user)); ?>" class="balance-adjust-form">
                <?php echo csrf_field(); ?>
                <input type="number"
                       name="amount"
                       class="md-input balance-adjust-input"
                       step="0.01"
                       min="0.01"
                       placeholder="Enter amount to add"
                       required>
                <?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <p class="balance-adjust-error"><?php echo e($message); ?></p>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                <button type="submit" class="md-btn md-btn-filled balance-adjust-btn">Add</button>
            </form>
        </div>
        <div class="balance-adjust-col">
            <form method="POST" action="<?php echo e(route('admin.users.balance.subtract', $user)); ?>" class="balance-adjust-form">
                <?php echo csrf_field(); ?>
                <input type="number"
                       name="amount"
                       class="md-input balance-adjust-input"
                       step="0.01"
                       min="0.01"
                       max="<?php echo e(max(0.01, (float) $user->balance)); ?>"
                       placeholder="Enter amount to subtract"
                       required>
                <?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <p class="balance-adjust-error"><?php echo e($message); ?></p>
                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                <button type="submit" class="md-btn md-btn-filled balance-adjust-btn">Subtract</button>
            </form>
        </div>
    </div>
    <p class="balance-adjust-hint">Current balance: <strong id="userBalanceHint">$<?php echo e(number_format($user->balance, 2)); ?></strong></p>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\SkyApps\Projects\Laravel_projects\web3derp\resources\views/admin/users/show.blade.php ENDPATH**/ ?>