<?php $__env->startSection('content'); ?>
    <p style="margin: 12px 0;">
        <a href="<?php echo e(url('admin/octoparse')); ?>">&larr; Back to Octoparse dashboard</a>
    </p>
    <h1 style="margin-top: 0;"><?php echo e($taskConfig['label'] ?? $taskId); ?></h1>
    <p>
        <small class="text-muted">Task ID:</small> <code><?php echo e($taskId); ?></code>
        <?php if(!empty($taskConfig['unique_key_field'])): ?>
            &middot;
            <small class="text-muted">Unique key:</small> <code><?php echo e($taskConfig['unique_key_field']); ?></code>
        <?php endif; ?>
    </p>

    <div class="row" style="margin-bottom: 12px;">
        <div class="col-md-6">
            <form method="get" class="form-inline">
                <div class="form-group">
                    <label for="octoparse-search" class="sr-only">Search</label>
                    <input type="text" name="q" id="octoparse-search" value="<?php echo e($search); ?>"
                           class="form-control" placeholder="Search external key or payload..." />
                </div>
                <button type="submit" class="btn btn-default">Search</button>
                <?php if($search !== ''): ?>
                    <a href="<?php echo e(url('admin/octoparse/tasks/' . $taskId)); ?>" class="btn btn-link">Clear</a>
                <?php endif; ?>
            </form>
        </div>
        <div class="col-md-6 text-right">
            <?php if($canRun && ($taskConfig['enabled'] ?? false)): ?>
                <form method="post" action="<?php echo e(url('admin/octoparse/run/' . $taskId)); ?>" style="display:inline;">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="btn btn-primary">Run now</button>
                </form>
            <?php endif; ?>
        </div>
    </div>

    <?php
        $sortLink = function ($col) use ($sort, $dir, $search) {
            $newDir = ($sort === $col && $dir === 'asc') ? 'desc' : 'asc';
            $params = array_filter([
                'q' => $search,
                'sort' => $col,
                'dir' => $newDir,
            ], fn($v) => $v !== '' && $v !== null);
            return '?' . http_build_query($params);
        };
        $arrow = fn($col) => $sort === $col ? ($dir === 'asc' ? ' ▲' : ' ▼') : '';
    ?>

    <table class="table table-condensed table-hover table-striped">
        <thead>
            <tr>
                <th style="width: 60px;"><a href="<?php echo e($sortLink('id')); ?>">ID<?php echo $arrow('id'); ?></a></th>
                <th><a href="<?php echo e($sortLink('external_key')); ?>">External key<?php echo $arrow('external_key'); ?></a></th>
                <th>Payload (preview)</th>
                <th style="width: 150px;"><a href="<?php echo e($sortLink('scraped_at')); ?>">Scraped at<?php echo $arrow('scraped_at'); ?></a></th>
                <th style="width: 150px;"><a href="<?php echo e($sortLink('imported_at')); ?>">Imported at<?php echo $arrow('imported_at'); ?></a></th>
            </tr>
        </thead>
        <tbody>
        <?php $__empty_1 = true; $__currentLoopData = $records; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $record): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                $payloadJson = json_encode($record->payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
                $payloadPreview = mb_substr($payloadJson, 0, 240);
                $modalId = 'octoparse-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>
                <td><?php echo e(optional($record->imported_at)->format('Y-m-d H:i') ?: '—'); ?></td>
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr>
                <td colspan="5" class="text-center text-muted">No records imported yet for this task.</td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>

    <div class="text-center" style="margin-bottom: 24px;">
        <?php echo e($records->links()); ?>

    </div>
<?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/task.blade.php ENDPATH**/ ?>