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

<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h1 class="fw-bold mb-0"><?= e(trans('my_review_assignments')) ?></h1>
        <div class="text-muted"><?= e(trans('reviewer_dashboard')) ?></div>
    </div>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-6">
        <div class="card border-0 shadow-sm rounded-4">
            <div class="card-body">
                <div class="small text-muted"><?= e(trans('pending_reviews')) ?></div>
                <div class="display-6 fw-bold"><?= e((string) ($summary['pending_count'] ?? 0)) ?></div>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card border-0 shadow-sm rounded-4">
            <div class="card-body">
                <div class="small text-muted"><?= e(trans('completed_reviews')) ?></div>
                <div class="display-6 fw-bold"><?= e((string) ($summary['completed_count'] ?? 0)) ?></div>
            </div>
        </div>
    </div>
</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('assignment_status')) ?></th>
                    <th><?= e(trans('due_date')) ?></th>
                    <th><?= e(trans('actions')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if (!empty($assignments)): ?>
                    <?php foreach ($assignments 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['due_date'] ?? '')) ?></td>
                            <td>
                                <div class="d-flex gap-2 flex-wrap">
                                    <?php if ((string) $row['status'] === 'assigned'): ?>
                                        <form method="post" action="<?= e(base_path('reviews/respond')) ?>" style="display:inline;">
                                            <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                            <input type="hidden" name="assignment_id" value="<?= e((string) $row['id']) ?>">
                                            <input type="hidden" name="action" value="accept">
                                            <button type="submit" class="btn btn-sm btn-success rounded-3"><?= e(trans('accept_assignment')) ?></button>
                                        </form>

                                        <form method="post" action="<?= e(base_path('reviews/respond')) ?>" style="display:inline;">
                                            <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                            <input type="hidden" name="assignment_id" value="<?= e((string) $row['id']) ?>">
                                            <input type="hidden" name="action" value="decline">
                                            <button type="submit" class="btn btn-sm btn-outline-danger rounded-3"><?= e(trans('decline_assignment')) ?></button>
                                        </form>
                                    <?php endif; ?>

                                    <?php if (in_array((string) $row['status'], ['accepted','completed'], true)): ?>
                                        <a href="<?= e(base_path('reviews/form?assignment_id=' . (int) $row['id'])) ?>" class="btn btn-sm btn-outline-primary rounded-3"><?= e(trans('review_form')) ?></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'; ?>
