<?php $__env->startSection('content'); ?>
    <div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
        <h1>Octoparse — Tasks &amp; data</h1>
        <?php if(count($tasks) > 0): ?>
            <a href="<?php echo e(route('admin.octoparse.export')); ?>" class="btn btn-default">
                <span class="glyphicon glyphicon-export"></span> Export Excel
            </a>
        <?php endif; ?>
    </div>

    <?php if(!$syncEnabled): ?>
        <div class="alert alert-warning">
            <strong>Scheduled sync is disabled.</strong>
            Set <code>OCTOPARSE_SYNC_ENABLED=true</code> in <code>.env</code> to enable the daily cron import.
        </div>
    <?php endif; ?>

    <?php if(count($tasks) === 0): ?>
        <div class="alert alert-info">
            No Octoparse tasks registered yet. Add entries under <code>tasks</code> in <code>config/octoparse.php</code>.
        </div>
    <?php else: ?>
        <div class="row" style="display: flex; flex-wrap: wrap;">
            <?php $__currentLoopData = $tasks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $taskId => $taskConfig): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                    $countRow = $counts[$taskId] ?? null;
                    $log = $lastLogs[$taskId] ?? null;
                    $enabled = (bool) ($taskConfig['enabled'] ?? false);
                ?>
                <div class="col-md-6 col-lg-4" style="margin-bottom: 20px; display: flex;">
                    <div class="panel panel-default" style="display: flex; flex-direction: column; width: 100%;">
                        <div class="panel-heading">
                            <strong><?php echo e($taskConfig['label'] ?? $taskId); ?></strong>
                            <?php if(!$enabled): ?>
                                <span class="label label-default pull-right">disabled</span>
                            <?php endif; ?>
                        </div>
                        <div class="panel-body" style="flex: 1;">
                            <p style="margin: 0 0 6px 0;">
                                <small class="text-muted">Task ID:</small>
                                <code><?php echo e($taskId); ?></code>
                            </p>
                            <?php if(!empty($taskConfig['unique_key_field'])): ?>
                                <p style="margin: 0 0 6px 0;">
                                    <small class="text-muted">Unique key:</small>
                                    <code><?php echo e($taskConfig['unique_key_field']); ?></code>
                                </p>
                            <?php endif; ?>
                            <p style="margin: 0 0 6px 0;">
                                <small class="text-muted">Stored records:</small>
                                <strong><?php echo e($countRow->total ?? 0); ?></strong>
                            </p>
                            <p style="margin: 0 0 6px 0;">
                                <small class="text-muted">Last import:</small>
                                <?php if($log): ?>
                                    <span style="margin-right: 5px;" class="label label-<?php echo e($log->status === 'success' ? 'success' : ($log->status === 'failed' ? 'danger' : ($log->status === 'partial' ? 'warning' : 'info'))); ?>">
                                        <?php echo e($log->status); ?>

                                    </span>
                                    <small><?php echo e(optional($log->started_at)->format('Y-m-d H:i')); ?></small>
                                <?php else: ?>
                                    <em>never</em>
                                <?php endif; ?>
                            </p>
                            <?php if(!empty($taskConfig['link'])): ?>
                                <p style="margin: 0 0 6px 0;">
                                    <small class="text-muted">Link:</small>
                                    <a href="<?php echo e($taskConfig['link']); ?>" target="_blank" rel="noopener noreferrer"><?php echo e($taskConfig['link']); ?></a>
                                </p>
                            <?php endif; ?>
                        </div>
                        <div class="panel-footer">
                            <a href="<?php echo e(url('admin/octoparse/tasks/' . $taskId)); ?>" class="btn btn-default btn-sm">
                                View records
                            </a>
                            <?php if($canRun && $enabled): ?>
                                <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 btn-sm">Run now</button>
                                </form>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>

        <?php if($canRun): ?>
            <div style="margin-top: 12px;">
                <form method="post" action="<?php echo e(url('admin/octoparse/run')); ?>" style="display:inline;">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="btn btn-primary">Run all enabled tasks</button>
                </form>
                <a href="<?php echo e(url('admin/octoparse/logs')); ?>" class="btn btn-default">View import logs</a>
            </div>
        <?php endif; ?>
    <?php endif; ?>
<?php $__env->stopSection(); ?>

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