<?php require __DIR__ . '/../../layouts/header.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="fw-bold mb-0"><?= e(trans('cron_logs')) ?></h1>
    <a href="<?= e(base_path('admin')) ?>" class="btn ec-btn btn-outline-secondary rounded-3"><?= e(trans('back')) ?></a>
</div>

<div class="ec-card   mb-4">
    <div class="ec-card-body">
        <form method="post" action="<?= e(base_path('admin/cron/run')) ?>" class="row g-3">
            <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">

            <div class="col-md-8">
                <label class="form-label"><?= e(trans('job_key')) ?></label>
                <select name="job_key" class="form-select rounded-3">
                    <option value="all">all</option>
                    <option value="submission_deadline_reminders">submission_deadline_reminders</option>
                    <option value="review_due_reminders">review_due_reminders</option>
                    <option value="decision_pending_reminders">decision_pending_reminders</option>
                    <option value="camera_ready_reminders">camera_ready_reminders</option>
                </select>
            </div>

            <div class="col-md-4 d-flex align-items-end">
                <button type="submit" class="btn ec-btn btn-success rounded-3 w-100"><?= e(trans('run_cron_now')) ?></button>
            </div>
        </form>
    </div>
</div>

<div class="ec-card  ">
    <div class="table-responsive">
        <table class="table ec-table align-middle mb-0">
            <thead class="table-light">
                <tr>
                    <th>#</th>
                    <th><?= e(trans('job_key')) ?></th>
                    <th><?= e(trans('started_at')) ?></th>
                    <th><?= e(trans('finished_at')) ?></th>
                    <th><?= e(trans('status')) ?></th>
                    <th><?= e(trans('created_notifications')) ?></th>
                    <th><?= e(trans('created_emails')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if (!empty($rows)): ?>
                    <?php foreach ($rows as $row): ?>
                        <tr>
                            <td><?= e((string) $row['id']) ?></td>
                            <td><?= e((string) $row['job_key']) ?></td>
                            <td><?= e((string) $row['started_at']) ?></td>
                            <td><?= e((string) ($row['finished_at'] ?? '')) ?></td>
                            <td><?= e((string) $row['status']) ?></td>
                            <td><?= e((string) $row['created_notifications']) ?></td>
                            <td><?= e((string) $row['created_emails']) ?></td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr><td colspan="7" class="text-center py-4"><?= e(trans('no_data')) ?></td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?php require __DIR__ . '/../../layouts/footer.php'; ?>
