<?php
    $fields = collect($fields);
    $readOnly = $readOnly ?? false;
    $prefilled = $prefilled ?? [];
    $scopeId = $scopeId ?? 'lvl_'.uniqid();
    $level = $level ?? 1;

    $childGroups = $fields->filter(fn($f) => $f->type === 'group')->values();
    $childOthers = $fields->filter(fn($f) => $f->type !== 'group')->values();
    $hasTabs = $childGroups->count() >= 1;
    $defaultTab = $childGroups->isNotEmpty() ? 'tab_'.$childGroups->first()->id : null;
?>

<?php if($childOthers->isNotEmpty()): ?>
    <div class="space-y-2 <?php echo e($hasTabs ? 'mb-4 pb-4 border-b border-slate-200' : ''); ?>">
        <?php $__currentLoopData = $childOthers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $child): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php echo $__env->make('partials.dynamic-field-input', ['field' => $child, 'readOnly' => $readOnly, 'prefilled' => $prefilled, 'level' => $level], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
<?php endif; ?>

<?php if($hasTabs): ?>
    <div x-data="{ activeTab: '<?php echo e($defaultTab); ?>' }" class="w-full">
        <?php if($level === 1): ?>
            
            <div class="relative mb-6">
                <div class="flex items-center gap-1 border-b border-slate-200 overflow-x-auto scroll-smooth flex-nowrap -mb-px">
                    <?php $__currentLoopData = $childGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <button type="button"
                                @click="activeTab = 'tab_<?php echo e($tab->id); ?>'"
                                :class="activeTab === 'tab_<?php echo e($tab->id); ?>'
                                    ? 'border-b-2 border-transtev-600 text-transtev-700 font-bold'
                                    : 'border-b-2 border-transparent text-slate-500 hover:text-slate-800 hover:border-slate-300'"
                                class="px-5 py-3 text-xs tracking-wider uppercase font-semibold whitespace-nowrap transition-all duration-200 -mb-[2px]">
                            <?php echo e($tab->label); ?>

                        </button>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>

            
            <?php $__currentLoopData = $childGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div x-show="activeTab === 'tab_<?php echo e($tab->id); ?>'" x-cloak class="group-content-scroll group-content-scroll--l1 space-y-2">
                    <?php echo $__env->make('partials.dynamic-fields-list', [
                        'fields' => $tab->children,
                        'readOnly' => $readOnly,
                        'prefilled' => $prefilled,
                        'scopeId' => $scopeId.'_'.$tab->id,
                        'level' => $level + 1,
                    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        <?php elseif($level === 2): ?>
            
            <div class="flex items-center gap-2 overflow-x-auto py-2 mb-6 scroll-smooth flex-nowrap">
                <?php $__currentLoopData = $childGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <button type="button"
                            @click="activeTab = 'tab_<?php echo e($tab->id); ?>'"
                            :class="activeTab === 'tab_<?php echo e($tab->id); ?>'
                                ? 'bg-transtev-600 text-white font-semibold shadow-sm'
                                : 'bg-white border border-slate-200 text-slate-600 hover:bg-slate-50 hover:text-slate-900'"
                            class="px-4 py-2 text-xs font-semibold rounded-full whitespace-nowrap transition-all duration-200">
                        <?php echo e($tab->label); ?>

                    </button>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            
            <?php $__currentLoopData = $childGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div x-show="activeTab === 'tab_<?php echo e($tab->id); ?>'" x-cloak class="group-content-scroll group-content-scroll--l2 space-y-2">
                    <?php echo $__env->make('partials.dynamic-fields-list', [
                        'fields' => $tab->children,
                        'readOnly' => $readOnly,
                        'prefilled' => $prefilled,
                        'scopeId' => $scopeId.'_'.$tab->id,
                        'level' => $level + 1,
                    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        <?php else: ?>
            
            <div class="flex items-center gap-6 overflow-x-auto py-1.5 mb-5 border-b border-slate-100 flex-nowrap">
                <?php $__currentLoopData = $childGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <button type="button"
                            @click="activeTab = 'tab_<?php echo e($tab->id); ?>'"
                            :class="activeTab === 'tab_<?php echo e($tab->id); ?>'
                                ? 'text-transtev-700 font-bold border-b-2 border-transtev-600'
                                : 'text-slate-500 hover:text-slate-800 border-b-2 border-transparent'"
                            class="px-1 py-2 text-xs font-semibold whitespace-nowrap transition-all duration-200 -mb-[8px]">
                        <?php echo e($tab->label); ?>

                    </button>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            
            <?php $__currentLoopData = $childGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div x-show="activeTab === 'tab_<?php echo e($tab->id); ?>'" x-cloak class="group-content-scroll group-content-scroll--l3 space-y-2">
                    <?php echo $__env->make('partials.dynamic-fields-list', [
                        'fields' => $tab->children,
                        'readOnly' => $readOnly,
                        'prefilled' => $prefilled,
                        'scopeId' => $scopeId.'_'.$tab->id,
                        'level' => $level + 1,
                    ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <?php endif; ?>
    </div>
<?php endif; ?>
<?php /**PATH C:\xampp\htdocs\teyssir\resources\views/partials/dynamic-fields-list.blade.php ENDPATH**/ ?>