@foreach($records as $record)
    @if($showHidden || (!$record->hidden && $record->hidden !== null))
        <tr class="record-level-{{ $indentation }}" style="padding-left: {{ $indentation * 20 }}px;">
            <td style="padding-left: {{ $indentation * 20 }}px;">
                {{ str_repeat('— ', $indentation) }}{{ $record->name }}
            </td>
            <td>{{ $record->type == 'IN' ? 'Entrata' : 'Uscita' }}</td>
            <td>
                <span class="badge tessera-badge {{ $record->enabled ? 'active' : 'suspended' }}">
                    {{ $record->enabled ? 'attivo' : 'disattivo' }}
                </span>
            </td>
            <td>
                <button type="button" class="btn btn--ui btn-sm" wire:click="addLevel({{ $record->id }})">Aggiungi livello</button>
                <button type="button" class="btn btn--ui btn-sm" wire:click="duplicate({{ $record->id }})">Duplica</button>
                <button type="button" class="btn" wire:click="edit({{ $record->id }})"><i class="fa-regular fa-pen-to-square"></i></button>

                @if($record->hidden)
                    <button type="button" class="btn" data-bs-content="Mostra" wire:click="show({{ $record->id }})"><i style="color: #3b994b" class="fa-regular fa-eye"></i></button>
                @else
                    <button type="button" class="btn" data-bs-content="Nascondi" onclick="confirm('Sei sicuro di voler nascondere questo elemento?') || event.stopImmediatePropagation()" wire:click="hide({{ $record->id }})"><i style="color: #be2828" class="fa-regular fa-eye-slash"></i></button>
                @endif
            </td>
        </tr>

        @if(count($record->childs))
            @include('livewire/causal_child', ['records' => $record->childs, 'indentation' => $indentation + 1])
        @endif
    @endif
@endforeach
