

<?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 action="<?php echo e(route('backend.top-services.store')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">Server<span class="required">*</span></label>
                        <select class="form-control" name="server_id" id="top-server-id" required>
                            <option value="">Select server</option>
                            <?php $__currentLoopData = $servers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($s->id); ?>"><?php echo e($s->server_name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">Service<span class="required">*</span></label>
                        <select class="form-control" name="service_id" id="top-service-id" required>
                            <option value="">Select server first</option>
                        </select>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">Status</label>
                        <select class="form-control" name="status">
                            <option value="1">On</option>
                            <option value="0">Off</option>
                        </select>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">Add top service</button>
            </form>
        </div>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="GET" action="<?php echo e(route('backend.top-services.index')); ?>" class="table-search-form">
                <div class="table-search">
                    <input type="text" name="search" class="search-input" placeholder="Search by server ID or service ID..." 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.top-services.index')); ?>" class="btn btn-outline">Clear</a>
                <?php endif; ?>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Server ID</th>
                        <th>Service ID</th>
                        <th>Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $topServices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ts): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($topServices->firstItem() + $loop->index); ?></td>
                        <td><?php echo e($ts->server_id); ?></td>
                        <td><?php echo e($ts->service_id); ?></td>
                        <td><?php echo e($ts->status == '1' ? 'On' : 'Off'); ?></td>
                        <td>
                            <form action="<?php echo e(route('backend.top-services.destroy', $ts->id)); ?>" method="post" class="d-inline" onsubmit="return confirm('Remove?');">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="table-btn"><i class="las la-trash"></i></button>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="5" class="text-center">No top services yet.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php echo e($topServices->links('vendor.pagination.default')); ?>

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

<?php $__env->startPush('script'); ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const serverSelect = document.getElementById('top-server-id');
    const serviceSelect = document.getElementById('top-service-id');
    if (!serverSelect || !serviceSelect) return;
    serverSelect.addEventListener('change', function() {
        const serverId = this.value;
        serviceSelect.innerHTML = '<option value="">Loading...</option>';
        if (!serverId) {
            serviceSelect.innerHTML = '<option value="">Select server first</option>';
            return;
        }
        fetch('<?php echo e(url("/backend/services-by-server")); ?>?server_id=' + encodeURIComponent(serverId))
            .then(r => r.json())
            .then(data => {
                serviceSelect.innerHTML = '<option value="">Select service</option>';
                (data.services || []).forEach(s => {
                    const opt = document.createElement('option');
                    opt.value = s.service_id;
                    opt.textContent = s.service_name + ' - ' + s.service_price;
                    serviceSelect.appendChild(opt);
                });
            })
            .catch(() => { serviceSelect.innerHTML = '<option value="">Select server first</option>'; });
    });
});
</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/top-services/index.blade.php ENDPATH**/ ?>