<?php $attributes ??= new \Illuminate\View\ComponentAttributeBag; ?>
<?php foreach($attributes->onlyProps([
    'name',
    'label' => '',
    'options' => [],
]) as $__key => $__value) {
    $$__key = $$__key ?? $__value;
} ?>
<?php $attributes = $attributes->exceptProps([
    'name',
    'label' => '',
    'options' => [],
]); ?>
<?php foreach (array_filter(([
    'name',
    'label' => '',
    'options' => [],
]), 'is_string', ARRAY_FILTER_USE_KEY) as $__key => $__value) {
    $$__key = $$__key ?? $__value;
} ?>
<?php $__defined_vars = get_defined_vars(); ?>
<?php foreach ($attributes as $__key => $__value) {
    if (array_key_exists($__key, $__defined_vars)) unset($$__key);
} ?>
<?php unset($__defined_vars); ?>

<div class="mb-4">
    <?php if($label): ?>
        <label class="block font-main text-size-small-heading leading-normal mb-2"><?php echo e($label); ?></label>
    <?php endif; ?>
    <div x-data="optionsList(<?php echo e(json_encode(old($name, $options))); ?>)" class="space-y-2">
        <template x-for="(option, index) in options" :key="index">
            <div class="flex gap-2">
                <input type="text" 
                       :name="`<?php echo e($name); ?>[${index}][key]`" 
                       x-model="option.key" 
                       class="flex-1 input-primary-input input-general" 
                       placeholder="Clave">
                <input type="text" 
                       :name="`<?php echo e($name); ?>[${index}][value]`" 
                       x-model="option.value" 
                       class="flex-1 input-primary-input input-general" 
                       placeholder="Valor">
                <?php if (isset($component)) { $__componentOriginal8565cc6e3559fc0755ba5bce504752a5 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal8565cc6e3559fc0755ba5bce504752a5 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.controls.button','data' => ['type' => 'button','variant' => 'remove','@click' => 'removeOption(index)']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('controls.button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'button','variant' => 'remove','@click' => 'removeOption(index)']); ?>Eliminar <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal8565cc6e3559fc0755ba5bce504752a5)): ?>
<?php $attributes = $__attributesOriginal8565cc6e3559fc0755ba5bce504752a5; ?>
<?php unset($__attributesOriginal8565cc6e3559fc0755ba5bce504752a5); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8565cc6e3559fc0755ba5bce504752a5)): ?>
<?php $component = $__componentOriginal8565cc6e3559fc0755ba5bce504752a5; ?>
<?php unset($__componentOriginal8565cc6e3559fc0755ba5bce504752a5); ?>
<?php endif; ?>
            </div>
        </template>
        <?php if (isset($component)) { $__componentOriginal8565cc6e3559fc0755ba5bce504752a5 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal8565cc6e3559fc0755ba5bce504752a5 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.controls.button','data' => ['type' => 'button','variant' => 'optional','@click' => 'addOption()']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('controls.button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'button','variant' => 'optional','@click' => 'addOption()']); ?>Agregar opción <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal8565cc6e3559fc0755ba5bce504752a5)): ?>
<?php $attributes = $__attributesOriginal8565cc6e3559fc0755ba5bce504752a5; ?>
<?php unset($__attributesOriginal8565cc6e3559fc0755ba5bce504752a5); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8565cc6e3559fc0755ba5bce504752a5)): ?>
<?php $component = $__componentOriginal8565cc6e3559fc0755ba5bce504752a5; ?>
<?php unset($__componentOriginal8565cc6e3559fc0755ba5bce504752a5); ?>
<?php endif; ?>
    </div>
</div>

<script>
    function optionsList(initial = []) {
        return {
            options: initial.length 
                ? initial.map(opt => ({ key: opt.key ?? '', value: opt.value ?? '' })) 
                : [{ key: '', value: '' }], // 👈 siempre empieza con uno
            addOption() {
                this.options.push({ key: '', value: '' });
            },
            removeOption(index) {
                this.options.splice(index, 1);
                if (this.options.length === 0) {
                    // 👇 evita que quede vacío, siempre deja al menos uno
                    this.options.push({ key: '', value: '' });
                }
            }
        }
    }
</script><?php /**PATH /home/cnllsandbox/public_html/house-contract.cnll-sandbox.com/resources/views/components/controls/options-list.blade.php ENDPATH**/ ?>