<?php $__env->startSection('title', 'Edit Voucher'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-3xl mx-auto">
    <div class="flex items-center gap-3 mb-6">
        <a href="<?php echo e(route('admin.vouchers.index')); ?>" class="text-gray-400 hover:text-gray-600 transition">
            <i class="fa-solid fa-arrow-left"></i>
        </a>
        <div>
            <h1 class="text-2xl font-bold text-gray-800">Edit Voucher</h1>
            <p class="text-gray-500 text-sm">
                <code class="bg-indigo-50 text-indigo-700 px-2 py-0.5 rounded font-mono"><?php echo e($voucher->code); ?></code>
            </p>
        </div>
    </div>

    <form method="POST" action="<?php echo e(route('admin.vouchers.update', $voucher)); ?>" class="space-y-6">
        <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>

        
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="font-semibold text-gray-700 mb-4 flex items-center gap-2">
                <i class="fa-solid fa-barcode text-indigo-500"></i> Kode Voucher
            </h2>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Kode Voucher <span class="text-red-500">*</span></label>
                <input type="text" name="code" value="<?php echo e(old('code', $voucher->code)); ?>" required
                       class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none uppercase font-mono"
                       style="text-transform:uppercase">
                <?php $__errorArgs = ['code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><p class="text-red-500 text-xs mt-1"><?php echo e($message); ?></p><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>
        </div>

        
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="font-semibold text-gray-700 mb-4 flex items-center gap-2">
                <i class="fa-solid fa-circle-info text-indigo-500"></i> Informasi Voucher
            </h2>

            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div class="sm:col-span-2">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Nama Voucher <span class="text-red-500">*</span></label>
                    <input type="text" name="name" value="<?php echo e(old('name', $voucher->name)); ?>" required
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                    <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><p class="text-red-500 text-xs mt-1"><?php echo e($message); ?></p><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <div class="sm:col-span-2">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Deskripsi</label>
                    <textarea name="description" rows="2"
                              class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none resize-none"><?php echo e(old('description', $voucher->description)); ?></textarea>
                </div>
            </div>
        </div>

        
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="font-semibold text-gray-700 mb-4 flex items-center gap-2">
                <i class="fa-solid fa-percent text-indigo-500"></i> Tipe Diskon
            </h2>

            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Tipe Diskon <span class="text-red-500">*</span></label>
                    <select name="type" id="type-select" onchange="toggleMaxDiscount(this.value)"
                            class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                        <option value="percentage" <?php echo e(old('type', $voucher->type) === 'percentage' ? 'selected' : ''); ?>>Persentase (%)</option>
                        <option value="fixed" <?php echo e(old('type', $voucher->type) === 'fixed' ? 'selected' : ''); ?>>Nominal Tetap (Rp)</option>
                    </select>
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1" id="discount-label">
                        Nilai Diskon <span class="text-red-500">*</span>
                    </label>
                    <input type="number" name="discount_value" value="<?php echo e(old('discount_value', $voucher->discount_value)); ?>" required step="0.01" min="0.01"
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Minimum Pembelian (Rp)</label>
                    <input type="number" name="min_purchase" value="<?php echo e(old('min_purchase', $voucher->min_purchase)); ?>" step="0.01" min="0"
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                </div>

                <div id="max-discount-field">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Maks. Nominal Diskon (Rp)</label>
                    <input type="number" name="max_discount" value="<?php echo e(old('max_discount', $voucher->max_discount)); ?>" step="0.01" min="0"
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                </div>
            </div>
        </div>

        
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="font-semibold text-gray-700 mb-4 flex items-center gap-2">
                <i class="fa-solid fa-calendar text-indigo-500"></i> Batas & Validitas
            </h2>

            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Maks. Penggunaan</label>
                    <input type="number" name="max_uses" value="<?php echo e(old('max_uses', $voucher->max_uses)); ?>" min="1"
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                </div>

                <div class="flex items-end">
                    <label class="flex items-center gap-2 cursor-pointer pb-1">
                        <input type="checkbox" name="is_active" value="1"
                               class="w-4 h-4 rounded text-indigo-600"
                               <?php echo e(old('is_active', $voucher->is_active) ? 'checked' : ''); ?>>
                        <span class="text-sm text-gray-700">Aktifkan voucher</span>
                    </label>
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Berlaku Mulai</label>
                    <input type="datetime-local" name="valid_from"
                           value="<?php echo e(old('valid_from', $voucher->valid_from?->format('Y-m-d\TH:i'))); ?>"
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Berlaku Sampai</label>
                    <input type="datetime-local" name="valid_until"
                           value="<?php echo e(old('valid_until', $voucher->valid_until?->format('Y-m-d\TH:i'))); ?>"
                           class="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:ring-2 focus:ring-indigo-400 outline-none">
                </div>
            </div>
        </div>

        <div class="flex justify-end gap-3">
            <a href="<?php echo e(route('admin.vouchers.index')); ?>"
               class="border border-gray-300 text-gray-600 px-6 py-2.5 rounded-lg hover:bg-gray-50 transition text-sm font-medium">
                Batal
            </a>
            <button type="submit"
                    class="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-2.5 rounded-lg transition text-sm font-medium">
                <i class="fa-solid fa-save mr-1"></i> Simpan Perubahan
            </button>
        </div>
    </form>
</div>

<script>
function toggleMaxDiscount(type) {
    const field = document.getElementById('max-discount-field');
    if (type === 'fixed') {
        field.classList.add('hidden');
    } else {
        field.classList.remove('hidden');
    }
}
toggleMaxDiscount(document.getElementById('type-select').value);
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\yasin\OneDrive\Desktop\PROJECT-VOUCHER\resources\views/admin/vouchers/edit.blade.php ENDPATH**/ ?>