<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="container-header">
        <h1><?php echo e($title); ?></h1>
    </div>

    <div class="card mb-25">
        <div class="card-body">
            <form method="get" action="<?php echo e(route('backend.smm-orders.index')); ?>" class="filter-form">
                <div class="row">
                    <div class="form-group width-33">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-control">
                            <option value="">All</option>
                            <option value="awaiting" <?php echo e(request('status') === 'awaiting' ? 'selected' : ''); ?>>Awaiting</option>
                            <option value="inprogress" <?php echo e(request('status') === 'inprogress' ? 'selected' : ''); ?>>In progress</option>
                            <option value="completed" <?php echo e(request('status') === 'completed' ? 'selected' : ''); ?>>Completed</option>
                            <option value="partial" <?php echo e(request('status') === 'partial' ? 'selected' : ''); ?>>Partial</option>
                            <option value="canceled" <?php echo e(request('status') === 'canceled' ? 'selected' : ''); ?>>Canceled</option>
                            <option value="error" <?php echo e(request('status') === 'error' ? 'selected' : ''); ?>>Error</option>
                            <option value="fail" <?php echo e(request('status') === 'fail' ? 'selected' : ''); ?>>Fail</option>
                        </select>
                    </div>
                    <div class="form-group width-33">
                        <label class="form-label">Search (ID or link)</label>
                        <input type="text" name="q" class="form-control" placeholder="Order ID or link" value="<?php echo e($search ?? ''); ?>">
                    </div>
                    <div class="form-group width-33">
                        <button class="btn btn-primary" type="submit">Filter</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="GET" action="<?php echo e(route('backend.smm-orders.index')); ?>" class="table-search-form">
                <?php if(request('status')): ?><input type="hidden" name="status" value="<?php echo e(request('status')); ?>"><?php endif; ?>
                <div class="table-search">
                    <input type="text" name="q" class="search-input" placeholder="Search by order ID or link..." value="<?php echo e($search ?? ''); ?>">
                    <i class="las la-search"></i>
                </div>
                <button type="submit" class="btn btn-secondary search-btn">Search</button>
                <?php if(!empty($search)): ?>
                    <a href="<?php echo e(route('backend.smm-orders.index', request()->only('status'))); ?>" class="btn btn-outline">Clear</a>
                <?php endif; ?>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Order ID</th>
                        <th>User</th>
                        <th>Service</th>
                        <th>Link</th>
                        <th>Qty</th>
                        <th>Charge</th>
                        <th>Status</th>
                        <th>Created</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($orders->firstItem() + $loop->index); ?></td>
                        <td><?php echo e($o->id); ?></td>
                        <td><?php echo e($o->user->email ?? $o->user_id); ?></td>
                        <td><?php echo e($o->smmService->name ?? '-'); ?></td>
                        <td><span class="text-ellipsis" title="<?php echo e($o->link); ?>"><?php echo e(Str::limit($o->link, 30)); ?></span></td>
                        <td><?php echo e($o->quantity); ?></td>
                        <td><?php echo e(number_format($o->charge, 2)); ?></td>
                        <td>
                            <?php
                                $statusClass = 'status';
                                if (in_array($o->status, ['completed'])) $statusClass = 'status success';
                                elseif (in_array($o->status, ['awaiting', 'inprogress'])) $statusClass = 'status pending';
                                elseif (in_array($o->status, ['error', 'fail', 'canceled'])) $statusClass = 'status failed';
                            ?>
                            <span class="<?php echo e($statusClass); ?>"><?php echo e(ucfirst($o->status)); ?></span>
                        </td>
                        <td><?php echo e($o->created_at?->format('Y-m-d H:i')); ?></td>
                        <td>
                            <div class="table-actions">
                                <button type="button" class="table-btn edit-smm-order" data-id="<?php echo e($o->id); ?>" data-link="<?php echo e($o->link); ?>" data-start-counter="<?php echo e($o->start_counter ?? ''); ?>" data-remains="<?php echo e($o->remains ?? ''); ?>" data-status="<?php echo e($o->status); ?>" title="Edit"><i class="las la-pen"></i></button>
                                <?php if(in_array($o->status, ['error', 'fail'])): ?>
                                <form action="<?php echo e(route('backend.smm-orders.resend', $o->id)); ?>" method="post" class="d-inline" onsubmit="return confirm('Resend this order to provider?');">
                                    <?php echo csrf_field(); ?>
                                    <button type="submit" class="table-btn" title="Resend"><i class="las la-redo"></i></button>
                                </form>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="10" class="text-center">No orders found.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php if($orders instanceof \Illuminate\Pagination\LengthAwarePaginator): ?>
        <div class="pagination-wrapper">
            <?php echo e($orders->links('vendor.pagination.default')); ?>

        </div>
        <?php endif; ?>
    </div>
</div>

<div class="modal" id="edit-smm-order-modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title">Edit order</h3>
            <button class="close-modal"><i class="las la-times"></i></button>
        </div>
        <form action="<?php echo e(route('backend.smm-orders.store')); ?>" method="post" id="edit-smm-order-form">
            <?php echo csrf_field(); ?>
            <input type="hidden" name="id" id="edit-order-id">
            <div class="modal-body">
                <div class="form-group mb-25">
                    <label class="form-label">Link</label>
                    <input type="text" class="form-control" name="link" id="edit-order-link" placeholder="https://">
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Start counter</label>
                    <input type="number" class="form-control" name="start_counter" id="edit-order-start-counter" min="0" placeholder="0">
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Remains</label>
                    <input type="number" class="form-control" name="remains" id="edit-order-remains" min="0" placeholder="0">
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Status<span class="required">*</span></label>
                    <select class="form-control" name="status" id="edit-order-status" required>
                        <option value="awaiting">Awaiting</option>
                        <option value="inprogress">In progress</option>
                        <option value="completed">Completed</option>
                        <option value="partial">Partial</option>
                        <option value="canceled">Canceled</option>
                        <option value="error">Error</option>
                        <option value="fail">Fail</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" type="submit">Update order</button>
            </div>
        </form>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
document.querySelectorAll('.edit-smm-order').forEach(function(btn) {
    btn.addEventListener('click', function() {
        var modal = document.getElementById('edit-smm-order-modal');
        document.getElementById('edit-order-id').value = this.getAttribute('data-id') || '';
        document.getElementById('edit-order-link').value = this.getAttribute('data-link') || '';
        document.getElementById('edit-order-start-counter').value = this.getAttribute('data-start-counter') || '';
        document.getElementById('edit-order-remains').value = this.getAttribute('data-remains') || '';
        document.getElementById('edit-order-status').value = this.getAttribute('data-status') || 'awaiting';
        modal.classList.add('active');
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.layout.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\HP\Desktop\product\smsflow\core\resources\views/backend/smm/orders/index.blade.php ENDPATH**/ ?>