<?php $__env->startSection('panel'); ?>

                    <div class="row">
        <div class="col-lg-12">
            <div class="card mt-3">

    <div class="card-header d-flex justify-content-between">
        <h5 class="card-title">Transfer Codes</h5>
        <button type="button" 
        class="btn btn-sm btn-outline--primary float-end form-generate-btn"
        data-bs-toggle="modal" 
        data-bs-target="#formGenerateModal">
    <i class="la la-fw la-plus"></i> Add New Code
</button>

    </div>

    <div class="card-body">

    <!-- Table Body here -->
<div class="table-responsive--sm table-responsive">
    <table class="table--light style--two table">
        <thead>
            <tr>
                <th>S.N.</th>
                <th>Code</th>
                <th>Name</th>
                <th>Sequence</th>
                <th>Status</th>
                <th>Action</th>
            </tr>
        </thead>

        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $codes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $code): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td><?php echo e($index + 1); ?></td>

                    <td>
                        <span class="text--primary fw-bold"><?php echo e($code->code); ?></span>
                    </td>
                    <td>
                        <span class="fw-bold"></span> <?php echo e($code->name); ?>

                    </td>
                    <td>
                        <span class="fw-bold"></span> <?php echo e($code->sequence); ?>

                    </td>

                    <td>
                        <?php if($code->status === 'active'): ?>
                            <span class="badge badge--success">Enabled</span>
                        <?php else: ?>
                            <span class="badge badge--danger">Disabled</span>
                        <?php endif; ?>
                    </td>

                    <td>
                        <div class="button--group">
                           <a href="#" 
   class="btn btn-sm btn-outline--primary edit-btn"
   data-id="<?php echo e($code->id); ?>"
   data-name="<?php echo e($code->name); ?>"
   data-code="<?php echo e($code->code); ?>"
   data-status="<?php echo e($code->status); ?>"
   data-sequence="<?php echo e($code->sequence); ?>"
   data-bs-toggle="modal" 
   data-bs-target="#formEditModal">
    <i class="la la-pencil"></i> Edit
</a>


                            <?php if($code->status === 'active'): ?>
                                <button class="btn btn-sm btn-outline--danger confirmationBtn"
                                    data-question="Are you sure to disable this bank?"
                                    data-action="<?php echo e(route('admin.wire.transfer.transfer.codes.status', $code->id)); ?>">
                                    <i class="la la-eye-slash"></i> Disable
                                </button>
                            <?php else: ?>
                                <button class="btn btn-sm btn-outline--success confirmationBtn"
                                    data-question="Are you sure to enable this bank?"
                                    data-action="<?php echo e(route('admin.wire.transfer.transfer.codes.status', $code->id)); ?>">
                                    <i class="la la-eye"></i> Enable
                                </button>
                            <?php endif; ?>
                        </div>
                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr>
                    <td colspan="6" class="text-center">No data available</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

    
    <!-- Table body ends -->
    </div>
</div>

                
                                    
        </div>
    </div>

        <div class="modal fade" id="formGenerateModal" tabindex="-1" aria-labelledby="formGenerateModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            
            <div class="modal-header">
                <h5 class="modal-title" id="formGenerateModalLabel">Generate Form</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>

            <form class="generate-form" action="<?php echo e(route('admin.wire.transfer.transfer.codes.save')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" name="name" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Code</label>
                        <input type="text" name="code" value="<?php echo e(generateTransferCode()); ?>" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Status</label>
                        <select name="status" class="form-control" required>
                            <option value="active">Active</option>
                            <option value="inactive">Inactive</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Sequence </label>
                        <input type="number" name="sequence" class="form-control" required>
                    </div>

                    <div class="form-group extra_area"></div>
                </div>

                <div class="modal-footer">
                    <button type="submit" class="btn btn--primary w-100 h-45 generatorSubmit">Add</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- Edit -->
 <div class="modal fade" id="formEditModal" tabindex="-1" aria-labelledby="formEditModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            
            <div class="modal-header">
                <h5 class="modal-title" id="formEditModalLabel">Edit Transfer Code</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>

            <form id="editForm" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>
                <div class="modal-body">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" name="name" id="editName" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Code</label>
                        <input type="text" name="code" id="editCode" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Status</label>
                        <select name="status" id="editStatus" class="form-control" required>
                            <option value="active">Active</option>
                            <option value="inactive">Inactive</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Sequence</label>
                        <input type="number" name="sequence" id="editSequence" class="form-control" required>
                    </div>
                </div>

                <div class="modal-footer">
                    <button type="submit" class="btn btn--primary w-100 h-45">Update</button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php $__env->startPush('script'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        const triggerBtn = document.querySelector('.form-generate-btn');
        const modalEl = document.getElementById('formGenerateModal');

        if (triggerBtn && modalEl) {
            triggerBtn.addEventListener('click', function () {
                const modal = new bootstrap.Modal(modalEl);
                modal.show();
            });
        }
    });

    document.addEventListener('click', function (e) {
    if (e.target.closest('.confirmationBtn')) {
        e.preventDefault();
        let actionUrl = e.target.closest('.confirmationBtn').dataset.action;

        if (confirm(e.target.closest('.confirmationBtn').dataset.question)) {
            window.location.href = actionUrl;
        }
    }
});

document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll('.edit-btn').forEach(btn => {
        btn.addEventListener('click', function () {
            let id = this.dataset.id;
            let name = this.dataset.name;
            let code = this.dataset.code;
            let status = this.dataset.status;
            let sequence = this.dataset.sequence;

            // Populate modal fields
            document.getElementById('editName').value = name;
            document.getElementById('editCode').value = code;
            document.getElementById('editStatus').value = status;
            document.getElementById('editSequence').value = sequence;

            // Set form action dynamically
            document.getElementById('editForm').action = `/admin/wire-transfer/transfer-codes/update/${id}`;
        });
    });
});


</script>
<?php $__env->stopPush(); ?>

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

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/qsaytzgc/primeestones.com/core/resources/views/admin/wire_transfer/transfer_codes.blade.php ENDPATH**/ ?>