<?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(has_permission('submissions.view_all') ? trans('submissions') : trans('my_submissions')) ?></h1>
    <?php if (has_permission('submissions.create')): ?>
        <a href="<?= e(base_path('submissions/create')) ?>" class="btn btn-success rounded-3"><?= e(trans('new_submission')) ?></a>
    <?php endif; ?>
</div>

<div class="card border-0 shadow-sm rounded-4">
    <div class="table-responsive">
        <table class="table align-middle mb-0">
            <thead class="table-light">
                <tr>
                    <th>#</th>
                    <th><?= e(trans('submission_no')) ?></th>
                    <th><?= e(trans('submission_title')) ?></th>
                    <th><?= e(trans('conference')) ?></th>
                    <th><?= e(trans('tracks')) ?></th>
                    <th><?= e(trans('status')) ?></th>
                    <th><?= e(trans('current_version')) ?></th>
                    <th><?= e(trans('actions')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if (!empty($submissions)): ?>
                    <?php foreach ($submissions as $row): ?>
                        <tr>
                            <td><?= e((string) $row['id']) ?></td>
                            <td><?= e((string) $row['submission_no']) ?></td>
                            <td><?= e((string) $row['title']) ?></td>
                            <td><?= e(current_lang() === 'ar' ? (string) $row['title_ar'] : (string) $row['title_en']) ?></td>
                            <td><?= e(current_lang() === 'ar' ? (string) $row['name_ar'] : (string) $row['name_en']) ?></td>
                            <td><span class="badge bg-primary"><?= e((string) $row['status']) ?></span></td>
                            <td><?= e((string) $row['current_version']) ?></td>
                            <td>
                                <div class="d-flex gap-2 flex-wrap">
                                    <a href="<?= e(base_path('submissions/show?id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-dark rounded-3"><?= e(trans('view_submission')) ?></a>

                                    <?php if (!has_permission('submissions.view_all')): ?>
                                        <a href="<?= e(base_path('submissions/edit?id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-primary rounded-3"><?= e(trans('edit_submission')) ?></a>

                                        <?php if ((string) $row['status'] === 'revision_required'): ?>
                                            <a href="<?= e(base_path('submissions/revision?id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-success rounded-3"><?= e(trans('upload_revision')) ?></a>
                                        <?php endif; ?>
                                    <?php endif; ?>

                                    <?php if (has_permission('reviews.view_all')): ?>
                                        <a href="<?= e(base_path('reviews/assignments?submission_id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-success rounded-3"><?= e(trans('manage_reviews')) ?></a>
                                        <a href="<?= e(base_path('reviews/submission?submission_id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-secondary rounded-3"><?= e(trans('review_summary')) ?></a>
                                    <?php endif; ?>

                                    <?php if (has_permission('decisions.make')): ?>
                                        <a href="<?= e(base_path('decisions/form?submission_id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-warning rounded-3"><?= e(trans('make_decision')) ?></a>
                                    <?php endif; ?>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr><td colspan="8" class="text-center py-4"><?= e(trans('no_data')) ?></td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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