<?php
    /**
     * Tabla de "Campos modificados" — presentación neutral.
     *
     * Recibe $changes directamente o $changesResolver (closure que recibe $record).
     * Cada elemento: ['key' => string, 'label' => string, 'before' => ?string, 'after' => ?string]
     *
     * Modos:
     * - Creación: before es null para todos → solo columna "Valor"
     * - Eliminación: after es null para todos → solo columna "Valor"
     * - Actualización: ambas columnas "Valor previo" / "Valor nuevo"
     */
    $record = $getRecord();

    if (isset($changesResolver) && is_callable($changesResolver)) {
        $changes = $changesResolver($record);
    }

    $changes = $changes ?? [];

    if (empty($changes)) {
        return;
    }

    // Detectar modo: creación (sin before), eliminación (sin after), o actualización (ambos)
    $hasAnyBefore = collect($changes)->contains(fn ($c) => $c['before'] !== null);
    $hasAnyAfter = collect($changes)->contains(fn ($c) => $c['after'] !== null);
    $isCreation = !$hasAnyBefore && $hasAnyAfter;
    $isDeletion = $hasAnyBefore && !$hasAnyAfter;
?>

<div class="credit-table-container">
    <table class="audit-changes-table credit-table">
        <thead>
            <tr>
                <th>Campo</th>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isCreation): ?>
                    <th>Valor</th>
                <?php elseif($isDeletion): ?>
                    <th>Valor</th>
                <?php else: ?>
                    <th class="audit-col-before">Valor previo</th>
                    <th class="audit-col-after">Valor nuevo</th>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </tr>
        </thead>
        <tbody>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $changes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $change): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                <tr>
                    <td class="audit-field-label"><?php echo e($change['label']); ?></td>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isCreation): ?>
                        <td><?php echo e($change['after']); ?></td>
                    <?php elseif($isDeletion): ?>
                        <td><?php echo e($change['before']); ?></td>
                    <?php else: ?>
                        <td class="audit-cell-before"><?php echo e($change['before'] ?? '—'); ?></td>
                        <td class="audit-cell-after"><?php echo e($change['after'] ?? '—'); ?></td>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </tr>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
        </tbody>
    </table>
</div>
<?php /**PATH /var/www/html/credifygo/resources/views/filament/infolists/components/audit-changes-table.blade.php ENDPATH**/ ?>