<?php
namespace App\Controllers;

use App\Models\ManagePMB;

class ManagePMBController
{
    protected $ManagePMB;

    public function __construct()
    {
        $this->ManagePMB = new ManagePMB();
    }

    public function index()
    {
        $status_akses = $this->ManagePMB->getStatusPmb();
        $status_soal = $this->ManagePMB->getStatusSoal();
        $tanggal_options = $this->ManagePMB->getTanggalHasilTes();
        $tahun_sekarang = date('Y');
        $gelombang_list = $this->ManagePMB->getGelombangList();

        require_once __DIR__ . '/../Views/admin/manage_pmb.php';
    }

    public function updateAksesPmb()
    {
        $status = $_POST['status_pmb'] ?? null;
        if ($status) {
            $this->ManagePMB->updateStatusPmb($status);
        }
        header('Location: /dashboard/admin-manage_pmb');
        exit;
    }

    public function updateStatusSoal()
    {
        $status = $_POST['status_pmb'] ?? null;
        if ($status) {
            $this->ManagePMB->updateStatusSoal($status);
        }
        header('Location: /dashboard/admin-manage_pmb');
        exit;
    }

    public function tambahGelombang()
    {
        $gelombang = $_POST['gelombang'];
        $tanggal = $_POST['tanggal'];
        $this->ManagePMB->tambahGelombang($gelombang, $tanggal);
        header('Location: /dashboard/admin-manage_pmb');
        exit;
    }

    public function editGelombang()
    {
        $id = $_POST['id_gel_pmb'];
        $gelombang = $_POST['gelombang'];
        $tanggal = $_POST['tanggal'];
        $this->ManagePMB->editGelombang($id, $gelombang, $tanggal);
        header('Location: /dashboard/admin-manage_pmb');
        exit;
    }

    public function hapusGelombang()
    {
        $id = $_POST['id_gel_pmb'];
        $this->ManagePMB->hapusGelombang($id);
        header('Location: /dashboard/admin-manage_pmb');
        exit;
    }

}
