<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header"><?php echo e(__('Edit QR Code')); ?></div>

                <div class="card-body">
                    <form method="POST" action="<?php echo e(route('qrs.update', $qr->id)); ?>" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>

                        <div class="row mb-3">
                            <label for="code" class="col-md-4 col-form-label text-md-end"><?php echo e(__('Unique Code')); ?></label>

                            <div class="col-md-6">
                                <input id="code" type="text" class="form-control <?php $__errorArgs = ['code'];
$__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); ?>" name="code" value="<?php echo e(old('code', $qr->code)); ?>" required autofocus>

                                <?php $__errorArgs = ['code'];
$__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" role="alert">
                                        <strong><?php echo e($message); ?></strong>
                                    </span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <!-- Stage 1 Image Drag & Drop -->
                        <div class="row mb-3">
                            <label for="stage1_image" class="col-md-4 col-form-label text-md-end"><?php echo e(__('Stage 1 QR Image')); ?></label>

                            <div class="col-md-6">
                                <div id="drop-zone-stage1" class="border-2 border-dashed border-secondary rounded p-4 text-center cursor-pointer">
                                    <p class="mb-2"><?php echo e(__('Drop image here or click to select')); ?></p>
                                    <input id="stage1_image" type="file" class="form-control d-none <?php $__errorArgs = ['stage1_image'];
$__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); ?>" name="stage1_image" accept="image/*">
                                    <img id="preview-stage1" class="img-thumbnail mt-2" style="max-width: 200px;" src="<?php echo e(asset('storage/' . $qr->stage1_image)); ?>">
                                </div>

                                <?php $__errorArgs = ['stage1_image'];
$__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 d-block" role="alert">
                                        <strong><?php echo e($message); ?></strong>
                                    </span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <!-- Stage 2 Image Drag & Drop -->
                        <div class="row mb-3">
                            <label for="stage2_image" class="col-md-4 col-form-label text-md-end"><?php echo e(__('Stage 2 QR Image')); ?></label>

                            <div class="col-md-6">
                                <div id="drop-zone-stage2" class="border-2 border-dashed border-secondary rounded p-4 text-center cursor-pointer">
                                    <p class="mb-2"><?php echo e(__('Drop image here or click to select')); ?></p>
                                    <input id="stage2_image" type="file" class="form-control d-none <?php $__errorArgs = ['stage2_image'];
$__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); ?>" name="stage2_image" accept="image/*">
                                    <img id="preview-stage2" class="img-thumbnail mt-2" style="max-width: 200px;" src="<?php echo e(asset('storage/' . $qr->stage2_image)); ?>">
                                </div>

                                <?php $__errorArgs = ['stage2_image'];
$__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 d-block" role="alert">
                                        <strong><?php echo e($message); ?></strong>
                                    </span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <!-- QR App Image Drag & Drop -->
                        <div class="row mb-3">
                            <label for="qr_app" class="col-md-4 col-form-label text-md-end"><?php echo e(__('QR App Image')); ?></label>

                            <div class="col-md-6">
                                <div id="drop-zone-qr-app" class="border-2 border-dashed border-secondary rounded p-4 text-center cursor-pointer">
                                    <p class="mb-2"><?php echo e(__('Drop image here or click to select (optional)')); ?></p>
                                    <input id="qr_app" type="file" class="form-control d-none <?php $__errorArgs = ['qr_app'];
$__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); ?>" name="qr_app" accept="image/*">
                                    <img id="preview-qr-app" class="img-thumbnail mt-2" style="max-width: 200px;" <?php if($qr->qr_app): ?> src="<?php echo e(asset('storage/' . $qr->qr_app)); ?>" <?php else: ?> class="d-none" <?php endif; ?>>
                                </div>

                                <?php $__errorArgs = ['qr_app'];
$__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 d-block" role="alert">
                                        <strong><?php echo e($message); ?></strong>
                                    </span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label for="status" class="col-md-4 col-form-label text-md-end"><?php echo e(__('Status')); ?></label>

                            <div class="col-md-6">
                                <select id="status" class="form-select <?php $__errorArgs = ['status'];
$__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); ?>" name="status" required>
                                    <option value="pending" <?php echo e($qr->status == 'pending' ? 'selected' : ''); ?>>Pending</option>
                                    <option value="scanned_1" <?php echo e($qr->status == 'scanned_1' ? 'selected' : ''); ?>>Scanned 1</option>
                                    <option value="scanned_2" <?php echo e($qr->status == 'scanned_2' ? 'selected' : ''); ?>>Scanned 2</option>
                                </select>

                                <?php $__errorArgs = ['status'];
$__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" role="alert">
                                        <strong><?php echo e($message); ?></strong>
                                    </span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <div class="row mb-0">
                            <div class="col-md-8 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    <?php echo e(__('Update')); ?>

                                </button>
                                <a href="<?php echo e(route('qrs.index')); ?>" class="btn btn-secondary">
                                    <?php echo e(__('Cancel')); ?>

                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function setupDropZone(dropZoneId, inputId, previewId, defaultSrc = null) {
    const dropZone = document.getElementById(dropZoneId);
    const input = document.getElementById(inputId);
    const preview = document.getElementById(previewId);

    dropZone.addEventListener('click', () => input.click());

    dropZone.addEventListener('dragover', (e) => {
        e.preventDefault();
        dropZone.classList.add('border-primary', 'bg-light');
    });

    dropZone.addEventListener('dragleave', () => {
        dropZone.classList.remove('border-primary', 'bg-light');
    });

    dropZone.addEventListener('drop', (e) => {
        e.preventDefault();
        dropZone.classList.remove('border-primary', 'bg-light');
        
        if (e.dataTransfer.files.length) {
            input.files = e.dataTransfer.files;
            updatePreview();
        }
    });

    input.addEventListener('change', updatePreview);

    function updatePreview() {
        const file = input.files[0];
        if (file) {
            const reader = new FileReader();
            reader.onload = (e) => {
                preview.src = e.target.result;
                preview.classList.remove('d-none');
            };
            reader.readAsDataURL(file);
        } else if (defaultSrc) {
            preview.src = defaultSrc;
            preview.classList.remove('d-none');
        }
    }
}

// Setup all drop zones
setupDropZone('drop-zone-stage1', 'stage1_image', 'preview-stage1', "<?php echo e(asset('storage/' . $qr->stage1_image)); ?>");
setupDropZone('drop-zone-stage2', 'stage2_image', 'preview-stage2', "<?php echo e(asset('storage/' . $qr->stage2_image)); ?>");
<?php if($qr->qr_app): ?>
setupDropZone('drop-zone-qr-app', 'qr_app', 'preview-qr-app', "<?php echo e(asset('storage/' . $qr->qr_app)); ?>");
<?php else: ?>
setupDropZone('drop-zone-qr-app', 'qr_app', 'preview-qr-app');
<?php endif; ?>
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/unitweb/bankid.unitweb.net/resources/views/qrs/edit.blade.php ENDPATH**/ ?>