<?php $__env->startSection('content'); ?>
    <p style="margin: 12px 0;">
        <a href="<?php echo e(url('admin/octoparse/logs')); ?>">&larr; Back to Octoparse import logs</a>
    </p>
    <h1 style="margin-top: 0;">
        Octoparse — New entries from import #<?php echo e($log->id); ?>

    </h1>
    <p>
        <small class="text-muted">Started at:</small>
        <code><?php echo e(optional($log->started_at)->format('Y-m-d H:i:s')); ?></code>
        &middot;
        <small class="text-muted">Finished at:</small>
        <code><?php echo e(optional($log->finished_at)->format('Y-m-d H:i:s') ?: '—'); ?></code>
        &middot;
        <small class="text-muted">Status:</small>
        <?php
            $badge = $log->status === 'success' ? 'success'
                : ($log->status === 'failed' ? 'danger'
                    : ($log->status === 'partial' ? 'warning' : 'info'));
        ?>
        <span class="label label-<?php echo e($badge); ?>"><?php echo e($log->status); ?></span>
    </p>

    <?php if(!$trackingAvailable): ?>
        <div class="alert alert-info">
            This import predates per-run new-entries tracking — only summary counts are available.
            Future imports will list their newly-inserted records here.
        </div>
    <?php elseif($recordsByTask->isEmpty()): ?>
        <div class="alert alert-info">
            <strong>No new entries were imported in this run.</strong>
            All scraped rows already existed and were re-upserted as updates.
        </div>
    <?php else: ?>
        <div class="alert alert-success">
            <strong><?php echo e($log->rows_inserted); ?></strong> new
            <?php echo e($log->rows_inserted === 1 ? 'record was' : 'records were'); ?> inserted in this run,
            across <?php echo e($recordsByTask->count()); ?>

            <?php echo e($recordsByTask->count() === 1 ? 'task' : 'tasks'); ?>.
        </div>

        <?php $__currentLoopData = $recordsByTask; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $taskId => $records): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
                $taskConfig = $tasks[$taskId] ?? [];
                $label = $taskConfig['label'] ?? $taskId;
            ?>
            <h3 style="margin-top: 24px;">
                <?php echo e($label); ?>

                <small><a href="<?php echo e(url('admin/octoparse/tasks/' . $taskId)); ?>">view all records →</a></small>
            </h3>
            <p style="margin: 0 0 8px 0;">
                <small class="text-muted">Task ID:</small> <code><?php echo e($taskId); ?></code>
                &middot;
                <small class="text-muted">New rows:</small> <strong><?php echo e($records->count()); ?></strong>
            </p>

            <table class="table table-condensed table-hover table-striped">
                <thead>
                    <tr>
                        <th style="width: 60px;">ID</th>
                        <th>External key</th>
                        <th>Payload (preview)</th>
                        <th style="width: 150px;">Scraped at</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $records; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $record): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $payloadJson = json_encode(
                                $record->payload,
                                JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
                            );
                            $payloadPreview = mb_substr($payloadJson, 0, 240);
                            $modalId = 'octoparse-new-row-' . $record->id;
                        ?>
                        <tr>
                            <td><?php echo e($record->id); ?></td>
                            <td style="word-break: break-all;"><?php echo e($record->external_key); ?></td>
                            <td>
                                <code style="white-space: pre-wrap;"><?php echo e($payloadPreview); ?><?php if(mb_strlen($payloadJson) > 240): ?>…<?php endif; ?></code>
                                <br>
                                <a href="#" data-toggle="modal" data-target="#<?php echo e($modalId); ?>">View full payload</a>
                                <div class="modal fade" id="<?php echo e($modalId); ?>" tabindex="-1" role="dialog">
                                    <div class="modal-dialog modal-lg" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                                <h4 class="modal-title">Record #<?php echo e($record->id); ?> — payload</h4>
                                            </div>
                                            <div class="modal-body">
                                                <pre style="max-height: 480px; overflow: auto;"><?php echo e($payloadJson); ?></pre>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td><?php echo e(optional($record->scraped_at)->format('Y-m-d H:i') ?: '—'); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.main', ['fluid' => true], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/resources/views/admin/octoparse/new-entries.blade.php ENDPATH**/ ?>