
<?php $__env->startSection('content'); ?>
<div class="container-fluid py-3">
    <div class="d-flex justify-content-end mb-3">
        <a href="<?php echo e(route('home')); ?>" class="btn-back">
            <i class="fas fa-arrow-left me-2"></i> Back to Dashboard
        </a>
    </div>

    <div class="row">
        <div class="col-lg-5">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-white py-3">
                    <h5 class="mb-0"><i class="fas fa-home me-2"></i> Add Home Currency</h5>
                </div>
                <div class="card-body">
                    <form method="POST" id="homeCurrencyForm" action="<?php echo e(route('home_currency.store')); ?>">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="id" id="homeCurrencyId">
                        <div id="timeout">
                            <?php if(Session::has('success')): ?>
                                <div class="alert alert-success"><?php echo e(Session('success')); ?></div>
                            <?php endif; ?>
                            <?php if(Session::has('error')): ?>
                                <div class="alert alert-danger"><?php echo e(Session('error')); ?></div>
                            <?php endif; ?>
                        </div>
                        <div class="mb-3">
                            <label class="form-label"><strong>Currency Code:</strong></label>
                            <input type="text" class="form-control" name="code" id="code" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label"><strong>Currency:</strong></label>
                            <select name="currency" id="currency" class="form-control" required>
                                <option value="" disabled selected>Select Currency</option>
                                <?php $__currentLoopData = $currencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($currency->id); ?>"><?php echo e($currency->symbol); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label class="form-label"><strong>Description:</strong></label>
                            <input type="text" class="form-control" name="description" id="description" required>
                        </div>
                        <div class="d-flex justify-content-end mt-4">
                            <input type="submit" id="submitButton" class="btn btn-primary me-2" value="SUBMIT">
                            <input type="reset" class="btn btn-outline-secondary" onclick="resetForm()" value="REFRESH">
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-lg-7 mt-4 mt-lg-0">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-white py-3">
                    <h5 class="mb-0"><i class="fas fa-list me-2"></i> Home Currency List</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead class="table-light">
                                <tr>
                                    <th>Date Captured</th>
                                    <th>Currency Code</th>
                                    <th>Description</th>
                                    <th style="width:100px">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $records; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $record): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($record->created_at->format('Y-m-d')); ?></td>
                                    <td><?php echo e($record->code); ?></td>
                                    <td><?php echo e($record->description); ?></td>
                                    <td class="text-center">
                                        <a href="#" class="btn btn-sm btn-primary" 
                                           onclick="editHomeCurrency(event, '<?php echo e($record->id); ?>', '<?php echo e($record->code); ?>', '<?php echo e($record->currency); ?>', '<?php echo e($record->description); ?>')">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <a href="<?php echo e(route('home_currency.delete', ['id' => $record->id])); ?>" class="btn btn-sm btn-danger deleteBtn">
                                            <i class="fas fa-trash-alt"></i>
                                        </a>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Delete Modal -->
<div class="modal fade" id="deleteConfirmModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-danger text-white">
                <h5 class="modal-title">Confirm Deletion</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                Are you sure you want to delete this home currency?
            </div>
            <div class="modal-footer">
                <button id="cancelDeleteBtn" type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button id="confirmDeleteBtn" type="button" class="btn btn-danger">Delete</button>
            </div>
        </div>
    </div>
</div>

<script>
    function editHomeCurrency(event, id, code, currencyId, description) {
        event.preventDefault();
        document.getElementById('homeCurrencyId').value = id;
        document.getElementById('code').value = code;
        document.getElementById('currency').value = currencyId;
        document.getElementById('description').value = description;
        document.querySelector('.card-header h5').innerHTML = '<i class="fas fa-home me-2"></i> Edit Home Currency';
        document.getElementById('submitButton').value = 'UPDATE';
        document.getElementById('homeCurrencyForm').action = '<?php echo e(route("home_currency.edit")); ?>';
    }

    function resetForm() {
        document.getElementById('homeCurrencyId').value = '';
        document.getElementById('code').value = '';
        document.getElementById('currency').selectedIndex = 0;
        document.getElementById('description').value = '';
        document.querySelector('.card-header h5').innerHTML = '<i class="fas fa-home me-2"></i> Add Home Currency';
        document.getElementById('submitButton').value = 'SUBMIT';
        document.getElementById('homeCurrencyForm').action = '<?php echo e(route("home_currency.store")); ?>';
        document.getElementById('timeout').innerHTML = '';
    }

   
</script>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        let deleteUrl = null;
        const modalEl = document.getElementById('deleteConfirmModal');
        const bsModal = new bootstrap.Modal(modalEl);

        // Show modal and store the delete URL
        document.querySelectorAll('.deleteBtn').forEach(btn => {
            btn.addEventListener('click', function (e) {
                e.preventDefault();
                deleteUrl = this.getAttribute('href');
                bsModal.show();
            });
        });

        // On confirm delete, redirect to delete URL
        document.getElementById('confirmDeleteBtn').addEventListener('click', function () {
            if (deleteUrl) {
                window.location.href = deleteUrl;
            }
        });

        // On cancel delete, just hide the modal — NO redirect
        document.getElementById('cancelDeleteBtn').addEventListener('click', function () {
            bsModal.hide(); // this dismisses the modal properly
        });
    });
</script>


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

<style>
.btn-back {
    text-decoration: none;
    color: #1AB9D9;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    padding: 5px 15px;
    border-radius: 4px;
    transition: all 0.3s;
}
.btn-back:hover {
    background-color: rgba(26, 185, 217, 0.1);
    text-decoration: none;
}
.card {
    border-radius: 8px;
    overflow: hidden;
    border: none;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}
.card-header {
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding: 12px 20px;
}
.table th {
    background-color: #f8f9fa;
}
</style>
<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH H:\systems\Quanta\demo\resources\views/maintanance/chart_of_accounts/createHomeCurrency.blade.php ENDPATH**/ ?>