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

<?php $__env->startSection('header'); ?>
    <div class="flex justify-between items-center">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            <?php echo e(__('Create Voucher')); ?>

        </h2>
        <a href="<?php echo e(route('isp.vouchers.index')); ?>" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
            Back to Vouchers
        </a>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="max-w-2xl mx-auto">
        <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
            <form method="POST" action="<?php echo e(route('isp.vouchers.store')); ?>" class="p-6 space-y-6">
                <?php echo csrf_field(); ?>
                
                <!-- Router Selection -->
                <div>
                    <label for="router_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Router <span class="text-red-500">*</span>
                    </label>
                    <select id="router_id" name="router_id" required
                            class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                        <option value="">Select a router</option>
                        <?php $__currentLoopData = $routers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $router): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($router->id); ?>"><?php echo e($router->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    <?php $__errorArgs = ['router_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Plan Selection -->
                <div>
                    <label for="plan_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Plan (Optional)
                    </label>
                    <select id="plan_id" name="plan_id"
                            class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                        <option value="">No specific plan</option>
                        <?php $__currentLoopData = $plans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $plan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($plan->id); ?>"><?php echo e($plan->name); ?> - KES <?php echo e(number_format($plan->price, 0)); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    <?php $__errorArgs = ['plan_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Voucher Type -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Voucher Type <span class="text-red-500">*</span>
                    </label>
                    <div class="space-y-2">
                        <label class="flex items-center">
                            <input type="radio" name="voucher_type" value="time" required
                                   class="rounded border-gray-300 text-blue-600 focus:ring-blue-500">
                            <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Time-based</span>
                        </label>
                        <label class="flex items-center">
                            <input type="radio" name="voucher_type" value="data" required
                                   class="rounded border-gray-300 text-blue-600 focus:ring-blue-500">
                            <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Data-based</span>
                        </label>
                    </div>
                    <?php $__errorArgs = ['voucher_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Time Limit (for time-based vouchers) -->
                <div id="time-fields" class="hidden">
                    <label for="time_limit_hours" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Time Limit (Hours) <span class="text-red-500">*</span>
                    </label>
                    <input type="number" id="time_limit_hours" name="time_limit_hours" min="1"
                           placeholder="e.g., 24 for 24 hours"
                           class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                    <?php $__errorArgs = ['time_limit_hours'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Data Limit (for data-based vouchers) -->
                <div id="data-fields" class="hidden">
                    <label for="data_limit_mb" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Data Limit (MB) <span class="text-red-500">*</span>
                    </label>
                    <input type="number" id="data_limit_mb" name="data_limit_mb" min="1"
                           placeholder="e.g., 1024 for 1GB"
                           class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                    <?php $__errorArgs = ['data_limit_mb'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Speed Profile -->
                <div>
                    <label for="speed_profile" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Speed Profile (Optional)
                    </label>
                    <input type="text" id="speed_profile" name="speed_profile"
                           placeholder="e.g., 1Mbps/512Kbps"
                           class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                    <?php $__errorArgs = ['speed_profile'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Price -->
                <div>
                    <label for="price" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Price (KES) <span class="text-gray-500">Optional</span>
                    </label>
                    <input type="number" id="price" name="price" min="0" step="0.01"
                           placeholder="e.g., 100"
                           class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                    <?php $__errorArgs = ['price'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Notes -->
                <div>
                    <label for="notes" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                        Notes (Optional)
                    </label>
                    <textarea id="notes" name="notes" rows="3"
                              placeholder="Additional notes about this voucher..."
                              class="w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"></textarea>
                    <?php $__errorArgs = ['notes'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <p class="mt-1 text-sm text-red-600"><?php echo e($message); ?></p>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <!-- Submit Button -->
                <div class="flex justify-end gap-3 pt-4 border-t border-gray-200 dark:border-gray-700">
                    <a href="<?php echo e(route('isp.vouchers.index')); ?>" 
                       class="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-gray-600">
                        Cancel
                    </a>
                    <button type="submit" 
                            class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">
                        Create Voucher
                    </button>
                </div>
            </form>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const voucherTypeRadios = document.querySelectorAll('input[name="voucher_type"]');
            const timeFields = document.getElementById('time-fields');
            const dataFields = document.getElementById('data-fields');

            function toggleFields() {
                const selectedType = document.querySelector('input[name="voucher_type"]:checked')?.value;
                
                if (selectedType === 'time') {
                    timeFields.classList.remove('hidden');
                    dataFields.classList.add('hidden');
                    document.getElementById('time_limit_hours').required = true;
                    document.getElementById('data_limit_mb').required = false;
                } else if (selectedType === 'data') {
                    timeFields.classList.add('hidden');
                    dataFields.classList.remove('hidden');
                    document.getElementById('time_limit_hours').required = false;
                    document.getElementById('data_limit_mb').required = true;
                } else {
                    timeFields.classList.add('hidden');
                    dataFields.classList.add('hidden');
                    document.getElementById('time_limit_hours').required = false;
                    document.getElementById('data_limit_mb').required = false;
                }
            }

            voucherTypeRadios.forEach(radio => {
                radio.addEventListener('change', toggleFields);
            });

            // Initial state
            toggleFields();
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\ispbilling\resources\views/isp/vouchers/create.blade.php ENDPATH**/ ?>