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

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="page-title"><?= e(trans('author_workflow')) ?></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  ">
    <div class="table-responsive">
        <table class="table ec-table align-middle mb-0">
            <thead>
                <tr>
                    <th>#</th>
                    <th><?= e(trans('submissions')) ?></th>
                    <th><?= e(trans('conference')) ?></th>
                    <th><?= e(trans('workflow_stage')) ?></th>
                    <th><?= e(trans('workflow_status')) ?></th>
                    <th><?= e(trans('review_rounds')) ?></th>
                    <th><?= e(trans('actions')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $row): ?>
                    <?php $wf = $model->workflowBySubmission((int) $row['id']); ?>
                    <?php $rounds = $model->roundRows((int) $row['id']); ?>
                    <tr>
                        <td><?= e((string) $row['id']) ?></td>
                        <td>
                            <div class="fw-bold"><?= e((string) ($row['title'] ?? '')) ?></div>
                            <div class="small text-muted"><?= e((string) ($row['submission_no'] ?? '')) ?></div>
                        </td>
                        <td><?= e(current_lang() === 'ar' ? (string) ($row['conference_title_ar'] ?? '') : (string) ($row['conference_title_en'] ?? '')) ?></td>
                        <td><?= e(trans(($wf['workflow_stage'] ?? 'submission') . '_stage')) ?></td>
                        <td><?= e(trans((string) ($wf['workflow_status'] ?? 'pending'))) ?></td>
                        <td>
                            <?php foreach ($rounds as $r): ?>
                                <div class="small">#<?= e((string) $r['round_no']) ?> — <?= e((string) $r['round_status']) ?></div>
                            <?php endforeach; ?>
                        </td>
                        <td>
                            <div class="d-flex flex-wrap gap-2">
                                <a href="<?= e(base_path('admin/author-workflow/edit?submission_id=' . (int) $row['id'])) ?>" class="btn ec-btn btn-sm btn-outline-primary rounded-3"><?= e(trans('edit')) ?></a>
                                <form method="post" action="<?= e(base_path('admin/review-rounds/open')) ?>" class="d-inline">
                                    <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                    <input type="hidden" name="submission_id" value="<?= e((string) $row['id']) ?>">
                                    <button class="btn ec-btn btn-sm btn-outline-success rounded-3"><?= e(trans('open_round')) ?></button>
                                </form>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($rows)): ?><tr><td colspan="7" class="text-center"><?= e(trans('no_data')) ?></td></tr><?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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