<?php
declare(strict_types=1);

namespace App\Controllers;

require_once BASE_PATH . '/app/helpers/permissions.php';

require_once BASE_PATH . '/app/helpers/conference_scope.php';

use App\Core\Controller;
use App\Core\Database;

final class ReviewController extends Controller
{
    public function index(): void
    {
        require_login();
        $orgId = (int) current_org_id();

        $db = Database::getInstance();
        $uid = (int)auth_id();

        $st = $db->prepare("
          SELECT ra.id AS assignment_id, ra.status, ra.due_date, ra.round_no,
                 s.id AS submission_id, s.title AS title_en, s.title_ar AS title_ar,
                 c.title_en AS conf_title_en, c.title_ar AS conf_title_ar
          FROM review_assignments ra
          JOIN submissions s ON s.id = ra.submission_id
          LEFT JOIN conferences c ON c.id = s.conference_id
          WHERE ra.reviewer_id = :uid
          AND submission_id IN (SELECT id FROM submissions WHERE conference_id IN (SELECT id FROM conferences WHERE org_id=".(int)$orgId."))  ORDER BY ra.id DESC
          LIMIT 300
        ");
        $st->execute([':uid'=>$uid, ':org_id' => $orgId]);
        $rows = $st->fetchAll();

        $this->view('review/index', ['rows'=>$rows]);
    }
}
