<?php $__env->startSection('title', 'Buat 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">Buat Voucher</h1>
            <p class="text-gray-500 text-sm">Isi form di bawah untuk membuat voucher baru</p>
        </div>
    </div>

    <form method="POST" action="<?php echo e(route('admin.vouchers.store')); ?>" x-data="voucherForm()" class="space-y-6">
        <?php echo csrf_field(); ?>

        
        <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 class="mb-4">
                <label class="flex items-center gap-2 cursor-pointer">
                    <input type="checkbox" name="auto_generate" value="1"
                           class="w-4 h-4 rounded text-indigo-600"
                           onchange="document.getElementById('code-section').classList.toggle('hidden', this.checked);
                                     document.getElementById('bulk-section').classList.toggle('hidden', !this.checked);"
                           <?php echo e(old('auto_generate') ? 'checked' : ''); ?>>
                    <span class="text-sm text-gray-700">Generate kode otomatis</span>
                </label>
            </div>

            <div id="code-section" class="<?php echo e(old('auto_generate') ? 'hidden' : ''); ?>">
                <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')); ?>"
                       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"
                       placeholder="Contoh: PROMO50 atau DISKON-2024"
                       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 id="bulk-section" class="<?php echo e(old('auto_generate') ? '' : 'hidden'); ?>">
                <label class="block text-sm font-medium text-gray-700 mb-1">Jumlah Voucher</label>
                <input type="number" name="bulk_count" value="<?php echo e(old('bulk_count', 1)); ?>" min="1" max="100"
                       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"
                       placeholder="Maksimal 100 voucher sekaligus">
                <p class="text-xs text-gray-400 mt-1">Kode akan digenerate otomatis (format: XXXX-XXXX)</p>
            </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')); ?>" 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"
                           placeholder="Contoh: Promo Hari Kemerdekaan">
                    <?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"
                              placeholder="Deskripsi singkat voucher ini..."><?php echo e(old('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', 'percentage') === 'percentage' ? 'selected' : ''); ?>>Persentase (%)</option>
                        <option value="fixed" <?php echo e(old('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')); ?>" 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"
                           placeholder="Contoh: 20">
                    <?php $__errorArgs = ['discount_value'];
$__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>
                    <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', 0)); ?>" 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"
                           placeholder="0 = tidak ada minimum">
                </div>

                <div id="max-discount-field" class="<?php echo e(old('type') === 'fixed' ? 'hidden' : ''); ?>">
                    <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')); ?>" 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"
                           placeholder="Kosongkan = tidak ada batas">
                </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')); ?>" 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"
                           placeholder="Kosongkan = tidak terbatas">
                </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', '1') ? 'checked' : ''); ?>>
                        <span class="text-sm text-gray-700">Aktifkan voucher ini</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')); ?>"
                           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')); ?>"
                           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 Voucher
            </button>
        </div>
    </form>
</div>

<script>
function toggleMaxDiscount(type) {
    const field = document.getElementById('max-discount-field');
    const label = document.getElementById('discount-label');
    if (type === 'fixed') {
        field.classList.add('hidden');
        label.innerHTML = 'Nilai Diskon (Rp) <span class="text-red-500">*</span>';
    } else {
        field.classList.remove('hidden');
        label.innerHTML = 'Nilai Diskon (%) <span class="text-red-500">*</span>';
    }
}
// Init on load
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/create.blade.php ENDPATH**/ ?>