

<?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.services.store')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">Service name<span class="required">*</span></label>
                        <input type="text" class="form-control" name="service_name" placeholder="e.g. WhatsApp" required>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">Service ID (code)<span class="required">*</span></label>
                        <input type="text" class="form-control" name="service_id" placeholder="e.g. wa" required>
                    </div>
                </div>
                <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" 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">Price<span class="required">*</span></label>
                        <input type="number" step="0.01" class="form-control" name="service_price" placeholder="0.00" required>
                    </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 service</button>
            </form>
        </div>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="get" action="<?php echo e(route('backend.services.index')); ?>" class="table-search-form">
                <?php if(request('server_id')): ?><input type="hidden" name="server_id" value="<?php echo e(request('server_id')); ?>"><?php endif; ?>
                <select name="server_id" class="form-control table-header-select" onchange="this.form.submit()">
                    <option value="">All servers</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(request('server_id') == $s->id ? 'selected' : ''); ?>><?php echo e($s->server_name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
                <div class="table-search-form__group">
                    <div class="table-search table-search--narrow">
                        <input type="text" name="search" class="search-input" placeholder="Search services..." 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.services.index', request()->only('server_id'))); ?>" class="btn btn-outline">Clear</a>
                    <?php endif; ?>
                </div>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Service name</th>
                        <th>Service ID</th>
                        <th>Server</th>
                        <th>Price</th>
                        <th>Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $services; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $svc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($services->firstItem() + $loop->index); ?></td>
                        <td><?php echo e($svc->service_name); ?></td>
                        <td><?php echo e($svc->service_id); ?></td>
                        <td><?php echo e($servers->firstWhere('id', $svc->server_id)->server_name ?? $svc->server_id); ?></td>
                        <td><?php echo e($svc->service_price); ?></td>
                        <td><?php echo e($svc->status == '1' ? 'On' : 'Off'); ?></td>
                        <td>
                            <div class="table-actions">
                                <button type="button" class="table-btn edit-service" data-id="<?php echo e($svc->id); ?>" data-service-name="<?php echo e($svc->service_name); ?>" data-service-id="<?php echo e($svc->service_id); ?>" data-server-id="<?php echo e($svc->server_id); ?>" data-service-price="<?php echo e($svc->service_price); ?>" data-status="<?php echo e($svc->status); ?>"><i class="las la-pen"></i></button>
                                <form action="<?php echo e(route('backend.services.destroy', $svc->id)); ?>" method="post" class="d-inline" onsubmit="return confirm('Delete this service?');">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('DELETE'); ?>
                                    <button type="submit" class="table-btn"><i class="las la-trash"></i></button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="7" class="text-center">No services yet.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php echo e($services->links('vendor.pagination.default')); ?>

    </div>
</div>

<div class="modal" id="edit-service-modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title">Edit service</h3>
            <button class="close-modal"><i class="las la-times"></i></button>
        </div>
        <form action="<?php echo e(route('backend.services.update', ['id' => '__ID__'])); ?>" method="post">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>
            <div class="modal-body">
                <div class="form-group mb-25">
                    <label class="form-label">Service name<span class="required">*</span></label>
                    <input type="text" class="form-control" name="service_name" placeholder="e.g. WhatsApp" required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Service ID (code)<span class="required">*</span></label>
                    <input type="text" class="form-control" name="service_id" placeholder="e.g. wa" required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Server<span class="required">*</span></label>
                    <select class="form-control" name="server_id" required>
                        <option value="">Select server</option>
                        <?php $__currentLoopData = $allServers ?? $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 mb-25">
                    <label class="form-label">Price<span class="required">*</span></label>
                    <input type="number" step="0.01" class="form-control" name="service_price" placeholder="0.00" required>
                </div>
                <div class="form-group mb-25">
                    <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>
            <div class="modal-footer">
                <button class="btn btn-primary" type="submit">Update service</button>
            </div>
        </form>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
document.querySelectorAll('.edit-service').forEach(function(btn) {
    btn.addEventListener('click', function() {
        const modal = document.getElementById('edit-service-modal');
        modal.querySelector('input[name="service_name"]').value = this.getAttribute('data-service-name') || '';
        modal.querySelector('input[name="service_id"]').value = this.getAttribute('data-service-id') || '';
        modal.querySelector('select[name="server_id"]').value = this.getAttribute('data-server-id') || '';
        modal.querySelector('input[name="service_price"]').value = this.getAttribute('data-service-price') || '';
        modal.querySelector('select[name="status"]').value = this.getAttribute('data-status') ?? '1';
        modal.querySelector('form').action = '<?php echo e(route("backend.services.update", ["id" => "__ID__"])); ?>'.replace('__ID__', this.getAttribute('data-id'));
        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\social\product\core\resources\views/backend/services/index.blade.php ENDPATH**/ ?>