<?php
    $logs = $record->statusLogs ?? collect();
    $refs = $logs
        ->map(fn ($log) => trim((string) ($log->orderDetail?->product_reference ?? '')))
        ->filter()
        ->unique()
        ->values()
        ->all();

    $imagesByRef = $refs !== []
        ? \App\Models\Universal\ProductImage::query()
            ->whereIn('reference_product', $refs)
            ->orderBy('id_product_images')
            ->get(['reference_product', 'link_image', 'id_product_images'])
            ->unique('reference_product')
            ->pluck('link_image', 'reference_product')
            ->all()
        : [];
?>

<div class="space-y-3">
    <div class="text-sm text-gray-600">
        Referencia: <span class="font-medium"><?php echo e($record->order_reference); ?></span>
    </div>

    <?php echo $__env->make('filament.orders.partials.order-progress', ['record' => $record], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <?php echo $__env->make('filament.orders.partials.order-steps', ['record' => $record], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <div class="overflow-x-auto rounded-lg border border-gray-200 bg-white">
        <table class="min-w-full text-sm">
            <thead class="bg-gray-50">
                <tr class="text-left text-gray-600">
                    <th class="px-3 py-2 font-medium whitespace-nowrap">Fecha</th>
                    <th class="px-3 py-2 font-medium">Estado</th>
                    <th class="px-3 py-2 font-medium">Detalle</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-200">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="align-top">
                        <td class="px-3 py-2 whitespace-nowrap"><?php echo e(optional($log->happened_at)->format('d/m/Y H:i') ?? '-'); ?></td>
                        <td class="px-3 py-2 whitespace-nowrap">
                            <?php
                                $rawStatus = (string) $log->status;
                                $normalizedStatus = \App\Models\Order::normalizeStatusCodeString($rawStatus);

                                $statusEnum = \App\Enums\OrderStatus::tryFrom($normalizedStatus);
                                $statusLabel = $statusEnum?->label() ?? ($normalizedStatus !== '' ? $normalizedStatus : $rawStatus);
                                $statusColor = $statusEnum?->filamentColor() ?? 'gray';
                            ?>

                            <?php if (isset($component)) { $__componentOriginal986dce9114ddce94a270ab00ce6c273d = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal986dce9114ddce94a270ab00ce6c273d = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'filament::components.badge','data' => ['color' => $statusColor]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('filament::badge'); ?>
<?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(['color' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($statusColor)]); ?>
                                <?php echo e($statusLabel); ?>

                             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal986dce9114ddce94a270ab00ce6c273d)): ?>
<?php $attributes = $__attributesOriginal986dce9114ddce94a270ab00ce6c273d; ?>
<?php unset($__attributesOriginal986dce9114ddce94a270ab00ce6c273d); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal986dce9114ddce94a270ab00ce6c273d)): ?>
<?php $component = $__componentOriginal986dce9114ddce94a270ab00ce6c273d; ?>
<?php unset($__componentOriginal986dce9114ddce94a270ab00ce6c273d); ?>
<?php endif; ?>
                        </td>
                        <td class="px-3 py-2">
                            <div><?php echo e($log->note ?? '-'); ?></div>

                            <?php
                                $sku = trim((string) ($log->orderDetail?->product_reference ?? ''));
                                $productName = trim((string) ($log->orderDetail?->product_name ?? ''));
                                $imageUrl = $sku !== '' ? ($imagesByRef[$sku] ?? null) : null;
                            ?>

                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($sku !== '' || $productName !== '' || filled($imageUrl)): ?>
                                <div class="mt-3 rounded-lg border border-gray-200 bg-gray-50 p-3">
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(filled($imageUrl)): ?>
                                        <img
                                            src="<?php echo e($imageUrl); ?>"
                                            alt="<?php echo e($productName !== '' ? $productName : 'Producto'); ?>"
                                            class="mb-2 h-16 w-16 rounded bg-white object-contain"
                                        >
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($sku !== ''): ?>
                                        <div class="text-sm text-gray-700">
                                            <span class="font-medium">SKU:</span> <?php echo e($sku); ?>

                                        </div>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($productName !== ''): ?>
                                        <div class="text-sm text-gray-700">
                                            <span class="font-medium">Producto:</span> <?php echo e($productName); ?>

                                        </div>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </div>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td class="px-3 py-4 text-gray-600" colspan="3">Sin historial.</td>
                    </tr>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php /**PATH /home/orderflowpro/public_html/resources/views/filament/orders/modals/status-log.blade.php ENDPATH**/ ?>