<?php

use iwbvel\classes\services\scheduler\Job_Presenter;

if (!defined('ABSPATH')) exit; // Exit if accessed directly 

if (empty($job) || empty($log) || !is_array($log)) {
    return;
}
?>

<div class="iwbvel-schedule-job-log-info">
    <div>
        <strong><?php esc_html_e('Job name:', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?> </strong>
        <span><?php echo esc_html($job->label); ?></span>
    </div>
    <?php if ($job->description != ''): ?>
        <div>
            <strong><?php esc_html_e('Description:', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?> </strong>
            <span><?php echo esc_html($job->description); ?></span>
        </div>
    <?php endif; ?>
    <div>
        <strong><?php esc_html_e('Created at:', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?> </strong>
        <span><?php echo esc_html(gmdate('Y-m-d H:i', strtotime($job->created_at))); ?></span>
    </div>
    <div>
        <strong><?php esc_html_e('Run for:', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?> </strong>
        <span><?php echo ($job->run_at == 'now') ? 'Now' : esc_html(ucfirst($job->run_for)); ?></span>
    </div>
    <div>
        <strong><?php esc_html_e('Status:', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?> </strong>
        <span><?php echo wp_kses_post(Job_Presenter::status($job->status)); ?></span>
    </div>
    <div>
        <strong><?php esc_html_e('Fields:', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?> </strong>
        <span><?php echo wp_kses_post(Job_Presenter::edit_items($job->edit_items)); ?></span>
    </div>
</div>

<div class="iwbvel-schedule-job-log-table">
    <table>
        <thead>
            <tr>
                <th><?php esc_html_e('Action', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></th>
                <th><?php esc_html_e('Run at', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($log as $iwbvel_item): ?>
                <tr>
                    <td><?php echo esc_html(Job_Presenter::log_action($iwbvel_item['action'])); ?></td>
                    <td><?php echo esc_html($iwbvel_item['datetime']); ?></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>