<?php
    $key = 'field_'.$field->id;
    $readOnly = $readOnly ?? false;
    $prefilled = $prefilled ?? [];
    if ($field->type === 'table') {
        $value = old($key.'.rows', $prefilled[$key] ?? []);
    } elseif ($field->type !== 'group') {
        $value = old($key, $prefilled[$key] ?? null);
    } else {
        $value = null;
    }
    $checkboxGroupValues = is_array($value) ? $value : (is_string($value) ? json_decode($value, true) ?? [] : []);
?>

<?php if($field->type === 'group'): ?>
    <?php if($field->children->isEmpty()): ?>
        <fieldset class="mb-6 rounded-xl border border-indigo-200 bg-indigo-50/30 p-5">
            <legend class="px-3 py-1 text-sm font-semibold text-indigo-800 bg-white border border-indigo-200 rounded-md"><?php echo e($field->label); ?></legend>
            <?php if(!empty($field->description)): ?>
                <p class="text-sm text-slate-500 mt-2"><?php echo e($field->description); ?></p>
            <?php endif; ?>
            <p class="text-sm text-slate-400 italic mt-3">Aucun champ dans ce groupe.</p>
        </fieldset>
    <?php else: ?>
        <div class="mb-6">
            <?php if(!empty($field->description)): ?>
                <p class="text-sm text-slate-500 mb-3 italic"><?php echo e($field->description); ?></p>
            <?php endif; ?>
            <?php echo $__env->make('partials.dynamic-fields-list', [
                'fields' => $field->children,
                'readOnly' => $readOnly,
                'prefilled' => $prefilled,
                'scopeId' => 'group_'.$field->id,
            ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        </div>
    <?php endif; ?>
<?php elseif($field->type === 'table'): ?>
    <?php echo $__env->make('partials.dynamic-table-field', ['field' => $field, 'value' => $value, 'readOnly' => $readOnly], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php else: ?>
<div class="mb-5">
    <label class="block text-sm font-medium text-slate-700 mb-1.5">
        <?php echo e($field->label); ?>

        <?php if($field->required && ! $readOnly): ?><span class="text-red-500">*</span><?php endif; ?>
    </label>
    <?php if(!empty($field->description)): ?>
        <p class="text-xs text-slate-500 mb-2 -mt-0.5"><?php echo e($field->description); ?></p>
    <?php endif; ?>

    <?php if($readOnly): ?>
        <div class="rounded-lg bg-slate-50 border border-slate-100 px-4 py-3 text-sm text-slate-800">
            <?php switch($field->type):
                case ('checkbox'): ?>
                    <?php echo e(($value === '1' || $value === true) ? 'Oui' : 'Non'); ?>

                    <?php break; ?>
                <?php case ('checkbox_group'): ?>
                    <?php echo e(!empty($checkboxGroupValues) ? implode(', ', $checkboxGroupValues) : '—'); ?>

                    <?php break; ?>
                <?php case ('file'): ?>
                    <?php if (isset($component)) { $__componentOriginale428ff3664af329988e8d13451374b90 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginale428ff3664af329988e8d13451374b90 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.file-preview','data' => ['path' => $value]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('file-preview'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['path' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($value)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginale428ff3664af329988e8d13451374b90)): ?>
<?php $attributes = $__attributesOriginale428ff3664af329988e8d13451374b90; ?>
<?php unset($__attributesOriginale428ff3664af329988e8d13451374b90); ?>
<?php endif; ?>
<?php if (isset($__componentOriginale428ff3664af329988e8d13451374b90)): ?>
<?php $component = $__componentOriginale428ff3664af329988e8d13451374b90; ?>
<?php unset($__componentOriginale428ff3664af329988e8d13451374b90); ?>
<?php endif; ?>
                    <?php break; ?>
                <?php default: ?>
                    <?php echo e($value ?: '—'); ?>

            <?php endswitch; ?>
        </div>
    <?php else: ?>
        <?php switch($field->type):
            case ('textarea'): ?>
                <textarea name="<?php echo e($key); ?>" rows="4" class="input-modern" <?php echo e($field->required ? 'required' : ''); ?>><?php echo e($value); ?></textarea>
                <?php break; ?>
            <?php case ('select'): ?>
                <select name="<?php echo e($key); ?>" class="input-modern" <?php echo e($field->required ? 'required' : ''); ?>>
                    <option value="">— Sélectionner —</option>
                    <?php $__currentLoopData = $field->options ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $option): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($option); ?>" <?php if($value == $option): echo 'selected'; endif; ?>><?php echo e($option); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
                <?php break; ?>
            <?php case ('radio'): ?>
                <div class="flex flex-wrap gap-4 mt-1">
                    <?php $__currentLoopData = $field->options ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $option): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <label class="inline-flex items-center gap-2 cursor-pointer">
                            <input type="radio" name="<?php echo e($key); ?>" value="<?php echo e($option); ?>" class="text-transtev-600 focus:ring-transtev-500" <?php if($value == $option): echo 'checked'; endif; ?> <?php echo e($field->required ? 'required' : ''); ?>>
                            <span class="text-sm text-slate-600"><?php echo e($option); ?></span>
                        </label>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <?php break; ?>
            <?php case ('checkbox'): ?>
                <label class="inline-flex items-center gap-2 cursor-pointer mt-1">
                    <input type="checkbox" name="<?php echo e($key); ?>" value="1" class="rounded border-slate-300 text-transtev-600" <?php if($value === '1' || $value === true): echo 'checked'; endif; ?>>
                    <span class="text-sm text-slate-600">Oui</span>
                </label>
                <?php break; ?>
            <?php case ('checkbox_group'): ?>
                <div class="space-y-2 mt-1">
                    <?php $__currentLoopData = $field->options ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $option): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <label class="flex items-center gap-2 cursor-pointer">
                            <input type="checkbox" name="<?php echo e($key); ?>[]" value="<?php echo e($option); ?>" class="rounded border-slate-300 text-transtev-600" <?php if(in_array($option, $checkboxGroupValues)): echo 'checked'; endif; ?>>
                            <span class="text-sm text-slate-600"><?php echo e($option); ?></span>
                        </label>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <?php break; ?>
            <?php case ('file'): ?>
                <?php if (isset($component)) { $__componentOriginal504fe35b8ae10dd8f883a20f1431f8b8 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal504fe35b8ae10dd8f883a20f1431f8b8 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.file-input','data' => ['name' => $key,'existing' => $value,'required' => $field->required]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('file-input'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['name' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($key),'existing' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($value),'required' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($field->required)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal504fe35b8ae10dd8f883a20f1431f8b8)): ?>
<?php $attributes = $__attributesOriginal504fe35b8ae10dd8f883a20f1431f8b8; ?>
<?php unset($__attributesOriginal504fe35b8ae10dd8f883a20f1431f8b8); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal504fe35b8ae10dd8f883a20f1431f8b8)): ?>
<?php $component = $__componentOriginal504fe35b8ae10dd8f883a20f1431f8b8; ?>
<?php unset($__componentOriginal504fe35b8ae10dd8f883a20f1431f8b8); ?>
<?php endif; ?>
                <?php break; ?>
            <?php default: ?>
                <input type="<?php echo e($field->type); ?>" name="<?php echo e($key); ?>" value="<?php echo e($value); ?>" class="input-modern" <?php echo e($field->required ? 'required' : ''); ?>>
        <?php endswitch; ?>
    <?php endif; ?>

    <?php $__errorArgs = [$key];
$__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.5 text-sm text-red-600"><?php echo e($message); ?></p>
    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
</div>
<?php endif; ?>
<?php /**PATH C:\xampp\htdocs\teyssir\resources\views/partials/dynamic-field-input.blade.php ENDPATH**/ ?>