

<?php $__env->startSection('content'); ?>
<main class="content">
    <div class="container-fluid p-0">

        <div class="row mb-3">
            <div class="col-auto">
                <h3>My Traders</h3>
                <?php if(!blank($client)): ?>
							<p><a href='<?php echo e(route("admin.user.single", $client->username)); ?>'>Back to User Page</a></p>
							<?php endif; ?>
							<input type="hidden" id="clid" value="<?php if(!blank($client)): ?> (<?php echo e($client->id); ?>) <?php endif; ?>" />
            </div>
        </div>

        <?php echo $__env->make('components.admin.error-message', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

        <div class="card">
            <div class="card-body table-responsive">
                <table class="table table-bordered align-middle">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>User ID</th>
                            <th>Copy Trader</th>
                            <th>Status</th>
                            <th>Created At</th>
                            <th width="220">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $myTraders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trader): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($trader->id); ?></td>
                                <td><?php echo e($trader->user_id); ?></td>
                                <td><?php echo e($trader->copyTrader?->name ?? '-'); ?></td>
                                <td>
                                    <span class="badge <?php echo e($trader->status == 'active' ? 'bg-success' : ($trader->status == 'paused' ? 'bg-warning' : 'bg-danger')); ?>">
                                        <?php echo e(ucfirst($trader->status ?? 'inactive')); ?>

                                    </span>
                                </td>
                                <td><?php echo e($trader->created_at->toDayDateTimeString()); ?></td>
                                <td>
                                    <div class="d-flex gap-2">
                                      <button type="button" class="btn btn-sm btn-primary"
        data-bs-toggle="modal"
        data-bs-target="#tradePanelModal<?php echo e($trader->id); ?>">
    Enter Trade
</button>

<!-- Trade Panel Modal -->
<div class="modal fade" id="tradePanelModal<?php echo e($trader->id); ?>" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <form method="POST" action="<?php echo e(route('admin.mytraders.submitTrade', $trader->id)); ?>" class="modal-content">
            <?php echo csrf_field(); ?>
            <div class="modal-header">
                <h5>Enter Trade - <?php echo e($trader->copyTrader?->name ?? '-'); ?></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body row g-3">
                <div class="col-md-6">
                    <label>Symbol / Trade</label>
                    <select name="symbol" class="form-select search-select" required>
                        <?php $__currentLoopData = \App\Models\Trade::where('is_active',1)->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($trade->id); ?>">
                                <?php echo e($trade->symbol); ?> - <?php echo e($trade->name); ?> ($<?php echo e($trade->ask_price); ?>)
                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
        

                <div class="col-md-6">
                    <label>Type</label>
                    <select name="type" class="form-select" required>
                        <option value="buy">Buy</option>
                        <option value="sell">Sell</option>
                    </select>
                </div>

                <div class="col-md-6">
                    <label>Volume</label>
                    <input type="number" step="0.0001" name="amount" class="form-control" required>
                </div>

                <div class="col-md-6">
                    <label>Interval</label>
                    <input type="text" name="interval" class="form-control" placeholder="e.g. 1h" required>
                </div>

                <div class="col-md-6">
                    <label>Leverage</label>
                    <input type="text" name="leverage" class="form-control" placeholder="e.g. 1x">
                </div>

                <div class="col-md-6">
                    <label>Payout</label>
                    <input type="text" name="payout" class="form-control" placeholder="Optional">
                </div>
                <div class="mb-3">
        <label class="form-label" for="inputTStatus">Status</label>
        <select class="form-control" name="status" id="inputTStatus" required>
            <?php echo get_order_edit_select(); ?>

        </select>
    </div>
    
    <div class="mb-3">
        <label class="form-label" for="inputTStatus">Win Status</label>
        <select class="form-control" name="wstatus" id="inputTStatus" >
            <option value="" >none</option>
            <option value="won"  >won</option>
            <option  value="loss" >loss</option>
        </select>
    </div>
            </div>

            <div class="modal-footer">
                <button class="btn btn-primary">Submit Trade</button>
            </div>
        </form>
    </div>
</div>


                                        <?php if($trader->status != 'paused'): ?>
                                        <form method="POST" action="<?php echo e(route('admin.mytraders.pause', $trader->id)); ?>">
                                            <?php echo csrf_field(); ?>
                                            <button class="btn btn-sm btn-warning" type="submit">Pause</button>
                                        </form>
                                        <?php endif; ?>
                                        
                                        <?php if($trader->status != 'active' && $trader->status != 'cancelled'): ?>
                                        <form method="POST" action="<?php echo e(route('admin.mytraders.resume', $trader->id)); ?>">
                                            <?php echo csrf_field(); ?>
                                            <button class="btn btn-sm btn-warning" type="submit">Resume</button>
                                        </form>
                                        <?php endif; ?>

                                        <?php if($trader->status != 'cancelled'): ?>
                                        <form method="POST" action="<?php echo e(route('admin.mytraders.cancel', $trader->id)); ?>">
                                            <?php echo csrf_field(); ?>
                                            <button class="btn btn-sm btn-danger" type="submit">Cancel</button>
                                        </form>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="6" class="text-center text-muted">No traders found.</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>

                <div class="mt-3">
                    <?php echo e($myTraders->links()); ?>

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

    </div>
</main>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).on('shown.bs.modal', '.modal', function () {
    console.log(typeof $.fn.select2); 
    const $modal = $(this); // modal container

    // find all select elements inside the modal
    $modal.find('select.search-select').each(function () {
        const $select = $(this); // the actual select inside modal

        // init only if not already initialized
        if (!$select.hasClass('select2-hidden-accessible')) {
            $select.select2({
                dropdownParent: $modal, // VERY important for modal
                width: '100%',
                placeholder: 'Search symbol...',
                allowClear: true
            });
        }
    });
});


</script>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/cmarkptp/api.cmarketindex.com/resources/views/admin/mytraders/index.blade.php ENDPATH**/ ?>