<div>
    <div class="row">
        <div class="col-md-6 d-flex justify-content-between mt-2 mb-2">
            <h4 class="fw-bold "><span class="text-muted fw-light"></span> Pre Claim</h4>
        </div>

        <div class="col-md-6 d-flex justify-content-end">
            <div class="col-md-9 mb-4">
                <input type="text" wire:model.live.debounce.300ms="searchBatches" value="" name="searchBatches" placeholder="Search batches" class="form-control search">
            </div>
        </div>
    </div>
    <!-- Striped Rows -->
    <div class="card">
        <div class="card-body">
            <div class="d-flex justify-content-end mb-2 mt-0">
                <button
                    type="button"
                    class="btn btn-primary"
                    data-bs-toggle="modal"
                    data-bs-target="#importModal"
                    data-bs-backdrop="static" data-bs-keyboard="false"
                    style="margin-left: 10px;"
                    ><strong><i class="bx bx-up-arrow-alt"></i>
                    Import</strong>
                </button>
                </a>
            </div>

            <div class="table-responsive text-nowrap">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>Batch #</th>
                        <th>File Name</th>
                        <th>File Path</th>
                        <th>Status</th>
                        <th>Created</th>
                        <th>Action</th>
                    </tr>
                    </thead>
                    <tbody class="table-border-bottom-0">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $batches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $batch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr wire:key="batch-row-<?php echo e($batch->id); ?>">
                            <td><?php echo e($batch->id); ?></td>
                            <td><strong><?php echo e($batch->batch_number ?? '-'); ?></strong></td>
                            <td><?php echo e($batch->file_name); ?></td>
                            <td><code><?php echo e($batch->file_path); ?></code></td>
                            <td>
                                <span class="badge <?php echo e((int) $batch->completed === 1 ? 'bg-label-success' : 'bg-label-warning'); ?>">
                                    <?php echo e((int) $batch->completed === 1 ? 'Completed' : 'Processing'); ?>

                                </span>
                            </td>
                            <td><?php echo e(optional($batch->created_at)->format('Y-m-d H:i')); ?></td>
                            <td>
                                <a class="btn btn-sm btn-primary"
                                   href="<?php echo e(route('admin.preclaim-data', $batch->id)); ?>">
                                    View Rows
                                </a>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="7" class="text-center">No batches found</td>
                        </tr>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </tbody>
                </table>

                <div class="mt-2">
                    <?php echo e($batches->links('pagination::bootstrap-5')); ?>

                </div>
            </div>
        </div>
    </div>

    <!-- Import Modal -->
    <div class="modal fade" id="importModal"  tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <form action="<?php echo e(route('admin.import-pre-claim')); ?>" method="POST" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="modalTitle">Import Pre Claim</h5>
                        <button
                            type="button"
                            class="btn-close"
                            data-bs-dismiss="modal"
                            aria-label="Close"
                        ></button>
                    </div>
                    <div class="modal-body">
                        <?php echo csrf_field(); ?>

                        <div class="row">
                            <div class="col mb-2">
                                <label for="description" class="form-label">File</label>
                                <input type="file" name="file" class="form-control <?php $__errorArgs = ['file'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" accept="csv, xlsx"/>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['file'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <span class="invalid-feedback"><strong><?php echo e($message); ?></strong></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </div>
            </form>
        </div>
    </div>


</div>

<?php $__env->startSection('script'); ?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
    $(document).ready(function(){
        function confirmDelete(id) {
            Swal.fire({
                title: 'Are you sure?',
                text: "This may effect on product listings",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes, delete it!'
            }).then((result) => {
                if (result.isConfirmed) {
                    window.Livewire.find('<?php echo e($_instance->getId()); ?>').call('delete', id)
                }
            });
        }

        $(document).on('click', '.delete', function(e) {
            e.preventDefault();

            // If icon is clicked instead of <a>, this ensures we still get correct data-id
            const id = $(e.target).closest('.delete').data('id');
            confirmDelete(id);
        });
    });

    $(document).ready(function(){
        $("#importModal").modal({
            backdrop: "static",
            keyboard: false,
        });
    });

    function copyToClipboard() {
        const text = $("#imagePath").text();
        console.log(text);
        navigator.clipboard.writeText(text).then(() => {
            document.getElementById("copyStatus").textContent = "Copied!";
        }).catch(err => {
            document.getElementById("copyStatus").textContent = "Failed to copy!";
            console.error("Failed to copy: ", err);
        });
    }

</script>

<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($errors->any()): ?>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#importModal").modal('show');
        });
    </script>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
<?php $__env->stopSection(); ?><?php /**PATH E:\laragon\www\medibill\resources\views/livewire/admin/pre-claim.blade.php ENDPATH**/ ?>