

<?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.otp-servers.store')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">Server name<span class="required">*</span></label>
                        <input type="text" class="form-control" name="server_name" placeholder="e.g. United States" required>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">Server code<span class="required">*</span></label>
                        <input type="text" class="form-control" name="server_code" placeholder="e.g. 12 or gb" required>
                        <small class="text-muted">Your internal code/name. Does not have to match provider.</small>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">Provider server ID<span class="required">*</span></label>
                        <input type="text" class="form-control" name="provider_server_id" placeholder="Exact provider country/server id, e.g. 0 or 12 or gb" required>
                        <small class="text-muted">Must match your API provider's country/server identifier exactly. This is what will be sent as the country parameter.</small>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">API<span class="required">*</span></label>
                        <select class="form-control" name="api_id" required>
                            <option value="">Select API</option>
                            <?php $__currentLoopData = $apiDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $api): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($api->id); ?>"><?php echo e($api->api_name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">Status<span class="required">*</span></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 server</button>
            </form>
        </div>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="GET" action="<?php echo e(route('backend.otp-servers.index')); ?>" class="table-search-form">
                <div class="table-search">
                    <input type="text" name="search" class="search-input" placeholder="Search by server name or code..." 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.otp-servers.index')); ?>" class="btn btn-outline">Clear</a>
                <?php endif; ?>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Server name</th>
                        <th>Server code</th>
                        <th>Provider server ID</th>
                        <th>API</th>
                        <th>Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $servers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($servers->firstItem() + $loop->index); ?></td>
                        <td><?php echo e($s->server_name); ?></td>
                        <td><?php echo e($s->server_code); ?></td>
                        <td><?php echo e($s->provider_server_id); ?></td>
                        <td><?php echo e($s->apiDetail->api_name ?? '-'); ?></td>
                        <td><?php echo e($s->status == '1' ? 'On' : 'Off'); ?></td>
                        <td>
                            <div class="table-actions">
                                <button type="button" class="table-btn edit-otp-server" data-id="<?php echo e($s->id); ?>" data-server-name="<?php echo e($s->server_name); ?>" data-server-code="<?php echo e($s->server_code); ?>" data-provider-server-id="<?php echo e($s->provider_server_id); ?>" data-api-id="<?php echo e($s->api_id); ?>" data-status="<?php echo e($s->status); ?>"><i class="las la-pen"></i></button>
                                <form action="<?php echo e(route('backend.otp-servers.destroy', $s->id)); ?>" method="post" class="d-inline" onsubmit="return confirm('Delete this server?');">
                                    <?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="6" class="text-center">No servers yet.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php echo e($servers->links('vendor.pagination.default')); ?>

    </div>
</div>

<div class="modal" id="edit-otp-server-modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title">Edit server</h3>
            <button class="close-modal"><i class="las la-times"></i></button>
        </div>
        <form action="<?php echo e(route('backend.otp-servers.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">Server name<span class="required">*</span></label>
                    <input type="text" class="form-control" name="server_name" placeholder="e.g. United States" required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Server code<span class="required">*</span></label>
                    <input type="text" class="form-control" name="server_code" placeholder="e.g. 12 or gb" required>
                    <small class="text-muted">Your internal code/name. Does not have to match provider.</small>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Provider server ID<span class="required">*</span></label>
                    <input type="text" class="form-control" name="provider_server_id" placeholder="Exact provider country/server id, e.g. 0 or 12 or gb" required>
                    <small class="text-muted">Must match your API provider's country/server identifier exactly. This is what will be sent as the country parameter.</small>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">API<span class="required">*</span></label>
                    <select class="form-control" name="api_id" required>
                        <option value="">Select API</option>
                        <?php $__currentLoopData = $apiDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $api): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($api->id); ?>"><?php echo e($api->api_name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Status<span class="required">*</span></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 server</button>
            </div>
        </form>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
document.querySelectorAll('.edit-otp-server').forEach(function(btn) {
    btn.addEventListener('click', function() {
        const modal = document.getElementById('edit-otp-server-modal');
        modal.querySelector('input[name="server_name"]').value = this.getAttribute('data-server-name') || '';
        modal.querySelector('input[name="server_code"]').value = this.getAttribute('data-server-code') || '';
        modal.querySelector('input[name="provider_server_id"]').value = this.getAttribute('data-provider-server-id') || '';
        modal.querySelector('select[name="api_id"]').value = this.getAttribute('data-api-id') || '';
        modal.querySelector('select[name="status"]').value = this.getAttribute('data-status') ?? '1';
        modal.querySelector('form').action = '<?php echo e(route("backend.otp-servers.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\upgraded\mine\core\resources\views/backend/otp-servers/index.blade.php ENDPATH**/ ?>