<?php $__env->startSection('content'); ?>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap4-toggle/css/bootstrap4-toggle.min.css">

<div class="card">
    <div class="card-header">
        <h4><?php echo e(trans('cruds.general_settings.title')); ?></h4>
    </div>
    <div class="card-body">
        <?php if(session('success')): ?>
            <div class="alert alert-success">
                <?php echo e(session('success')); ?>

            </div>
        <?php endif; ?>
        <form action="<?php echo e(route('admin.general_settings.update')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <?php $__currentLoopData = $settings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="form-group">
                    <label><?php echo e(ucwords(str_replace('_', ' ', $value->key))); ?></label>
                    <?php if($value->type == 'text'): ?>
                        <input type="text" name="<?php echo e($value->key); ?>" value="<?php echo e($value->value); ?>" class="form-control" required>
                    <?php elseif($value->type == 'dropdown'): ?>
                        <select name="<?php echo e($value->key); ?>" class="form-control" required>
                            <option value="enable" <?php echo e($value->value == 'enable' ? 'selected' : ''); ?>>Enable</option>
                            <option value="disable" <?php echo e($value->value == 'disable' ? 'selected' : ''); ?>>Disable</option>
                        </select>  
                    <?php elseif($value->type == 'switch'): ?>
                        <?php
                            $payment_option = json_decode($value->value, true);
                            $text = $payment_option['text'] ?? 'Cash Payment';
                            $currentValue = $payment_option['value'] ?? 0;
                        ?>

                        <div class="payment-switch-wrapper">
                            <br><label><?php echo e($text); ?></label>

                            <!-- Hidden input -->
                            <input type="hidden" name="<?php echo e($value->key); ?>" class="payment-hidden" value='<?php echo e(json_encode(["text" => $text, "value" => $currentValue])); ?>'>

                            <!-- Toggle -->
                            <input type="checkbox" class="toggle-flag" data-toggle="toggle" data-on="Enable" data-off="Disable" data-size="sm" data-onstyle="success" data-offstyle="danger" <?php echo e($currentValue == 1 ? 'checked' : ''); ?> >
                        </div>
                    <?php endif; ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            
            <div class="row">
                <div class="col-12 text-end">
                    <button class="btn btn-primary btn-primary-hover" type="submit"><?php echo e(trans('global.save')); ?></button>
                </div>
            </div>
        </form>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>

    <script>
        $(document).ready(function () {
            $('.toggle-flag').on('change', function () {
                let $wrapper = $(this).closest('.payment-switch-wrapper');
                let $hiddenInput = $wrapper.find('.payment-hidden');

                if ($hiddenInput.length === 0) {
                    console.error('Hidden input not found');
                    return;
                }

                let data = JSON.parse($hiddenInput.val());

                // ✅ Enable = 1, Disable = 0
                data.value = $(this).prop('checked') ? 1 : 0;

                $hiddenInput.val(JSON.stringify(data));

                console.log('Updated value:', $hiddenInput.val());
            });
        });
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/resources/views/admin/general_settings/form.blade.php ENDPATH**/ ?>