

<?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.api-details.store')); ?>" method="post">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">API name<span class="required">*</span></label>
                        <input type="text" class="form-control" name="api_name" placeholder="e.g. smsbower" required>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">API URL<span class="required">*</span></label>
                        <input type="url" class="form-control" name="api_url" placeholder="https://..." required>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group width-50">
                        <label class="form-label">API key<span class="required">*</span></label>
                        <input type="text" class="form-control" name="api_key" placeholder="API key" required>
                    </div>
                    <div class="form-group width-50">
                        <label class="form-label">Provider type<span class="required">*</span></label>
                        <select name="provider_type" class="form-control" required>
                            <option value="handler" selected>PHP handler_api.php</option>
                            <option value="laravel">Laravel /api/v1</option>
                        </select>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">Add API</button>
            </form>
        </div>
    </div>

    <div class="card table-card">
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Balance</th>
                        <th>URL</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $apis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $api): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($loop->iteration); ?></td>
                        <td><?php echo e($api->api_name); ?></td>
                        <td><?php echo e($balances[$api->id] ?? '—'); ?></td>
                        <td><?php echo e(Str::limit($api->api_url, 40)); ?></td>
                        <td>
                            <div class="table-actions">
                                <button
                                    type="button"
                                    class="table-btn edit-api-detail"
                                    data-id="<?php echo e($api->id); ?>"
                                    data-api-name="<?php echo e($api->api_name); ?>"
                                    data-api-url="<?php echo e($api->api_url); ?>"
                                    data-api-key="<?php echo e($api->api_key); ?>"
                                    data-provider-type="<?php echo e($api->provider_type ?? 'handler'); ?>"
                                >
                                    <i class="las la-pen"></i>
                                </button>
                                <form action="<?php echo e(route('backend.api-details.destroy', $api->id)); ?>" method="post" class="d-inline" onsubmit="return confirm('Delete this API?');">
                                    <?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="5" class="text-center">No API details yet.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal" id="edit-api-detail-modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title">Edit API</h3>
            <button class="close-modal"><i class="las la-times"></i></button>
        </div>
        <form action="<?php echo e(route('backend.api-details.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">API name<span class="required">*</span></label>
                    <input type="text" class="form-control" name="api_name" placeholder="e.g. smsbower" required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">API URL<span class="required">*</span></label>
                    <input type="url" class="form-control" name="api_url" placeholder="https://..." required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">API key<span class="required">*</span></label>
                    <input type="text" class="form-control" name="api_key" placeholder="API key" required>
                </div>
                <div class="form-group mb-25">
                    <label class="form-label">Provider type<span class="required">*</span></label>
                    <select name="provider_type" class="form-control" required>
                        <option value="handler">PHP handler_api.php</option>
                        <option value="laravel">Laravel /api/v1</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" type="submit">Update API</button>
            </div>
        </form>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
document.querySelectorAll('.edit-api-detail').forEach(function(btn) {
    btn.addEventListener('click', function() {
        const modal = document.getElementById('edit-api-detail-modal');
        modal.querySelector('input[name="api_name"]').value = this.getAttribute('data-api-name') || '';
        modal.querySelector('input[name="api_url"]').value = this.getAttribute('data-api-url') || '';
        modal.querySelector('input[name="api_key"]').value = this.getAttribute('data-api-key') || '';
        const typeSelect = modal.querySelector('select[name="provider_type"]');
        if (typeSelect) {
            typeSelect.value = this.getAttribute('data-provider-type') || 'handler';
        }
        modal.querySelector('form').action = '<?php echo e(route("backend.api-details.update", ["id" => "__ID__"])); ?>'.replace('__ID__', this.getAttribute('data-id'));
    });
});
</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\nbverify\mine\resources\views/backend/api-details/index.blade.php ENDPATH**/ ?>