<?php

namespace App\Controllers;

use Core\Database;

class AjuanMhsController
{
    public function index()
    {
        $nim = $_SESSION['user']['nim'] ?? null;
        $pdo = Database::getConnection();

        $data = [];

        // Daftar semester yang valid untuk setiap jenis ajuan
        $semesters = [
            'pplk'     => [6, 7, 8],
            'kkn'      => [6, 7, 8],
            'skripsi'  => [8, 10, 12, 14, 16, 18, 20],
            'yudisium' => [8, 10, 12, 14, 16, 18, 20],
            'wisuda'   => [8, 10, 12, 14, 16, 18, 20],
            'transkip' => [8, 10, 12, 14, 16, 18, 20],
        ];

        foreach ($semesters as $key => $smtList) {
            $inClause = implode(',', $smtList); // Buat jadi string: "8,10,12,..."
            $stmt = $pdo->prepare("
                SELECT * FROM tb_kelas 
                WHERE nim = :nim 
                  AND smt IN ($inClause) 
            ");
            $stmt->execute(['nim' => $nim]);

            $data["show_$key"] = $stmt->rowCount() > 0;
        }

        extract($data);

        require_once __DIR__ . '/../Views/mahasiswa/mahasiswa_ajukan.php';
    }
}
