<?php

use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Config\Services;

/**
 * @var RouteCollection $routes
 */
$routes->set404Override(function () {
    return view('404notfound');
});
$routes->get('notallow', function () {
    // Ambil service View untuk memuat view
    $view = Services::renderer();

    // Tampilkan view 404 secara langsung
    return $view->render('notallow'); // Ganti '404' dengan nama view Anda
});
$routes->get('maintenance', 'Home::maintenance');
$routes->get('apisekolah', 'ApiSekolah::index');
$routes->get('/', 'Home::index', ['filter' => 'role:admin,guru']);
$routes->group('home', ['filter' => 'role:admin,guru'], function ($routes) {
    $routes->get('/',  'Home::index');
    $routes->get('getrombel',  'Home::getrombel');
    $routes->get('getabsensi',  'Home::getabsensi');
    $routes->get('getperingkat',  'Home::getperingkat');
    $routes->get('getlogs',  'Home::getlogs');
});
$routes->group('user', ['filter' => 'role:admin'], function ($routes) {
    $routes->get('/', 'User::index',);
    $routes->get('getUsers', 'User::getUsers');
    $routes->get('edit/(:num)', 'User::edit/$1');
    $routes->post('add', 'User::add');
    $routes->post('update', 'User::update');
    $routes->post('updateprofil', 'User::updateprofil');
    $routes->delete('delete/(:num)', 'User::delete/$1');
    $routes->post('import', 'User::importViaAjax');
});
$routes->group('referensi', ['filter' => 'role:admin,guru'], function ($routes) {
    $routes->group('tahunpelajaran', function ($routes) {
        $routes->get('/', 'TahunPelajaran::index');
        $routes->get('getdata', 'TahunPelajaran::getData');
        $routes->get('edit/(:num)', 'TahunPelajaran::edit/$1');
        $routes->post('add', 'TahunPelajaran::add');
        $routes->post('update', 'TahunPelajaran::update');
        $routes->delete('delete/(:num)', 'TahunPelajaran::delete/$1');
    });
    $routes->group('tingkat', function ($routes) {
        $routes->get('/', 'Tingkat::index');
        $routes->get('getdata', 'Tingkat::getData');
        $routes->get('edit/(:num)', 'Tingkat::edit/$1');
        $routes->post('add', 'Tingkat::add');
        $routes->post('update', 'Tingkat::update');
        $routes->delete('delete/(:num)', 'Tingkat::delete/$1');
    });
    $routes->group('matapelajaran', function ($routes) {
        $routes->get('/', 'MataPelajaran::index');
        $routes->get('getdata', 'MataPelajaran::getData');
        $routes->get('edit/(:num)', 'MataPelajaran::edit/$1');
        $routes->post('add', 'MataPelajaran::add');
        $routes->post('update', 'MataPelajaran::update');
        $routes->delete('delete/(:num)', 'MataPelajaran::delete/$1');
    });
    $routes->group('tujuan', function ($routes) {
        $routes->get('/', 'Tujuan::index');
        $routes->get('gettujuan/(:num)', 'Tujuan::getTujuan/$1');
        $routes->get('getpembelajaran', 'Tujuan::getPembelajaran');
        $routes->get('edit/(:num)', 'Tujuan::edit/$1');
        $routes->post('add', 'Tujuan::addTujuan');
        $routes->post('update', 'Tujuan::update');
        $routes->delete('delete/(:num)', 'Tujuan::delete/$1');
        $routes->post('copytujuan', 'Tujuan::CopyTujuan');
    });
    $routes->group('rombel', function ($routes) {
        $routes->get('/', 'Rombel::index');
        $routes->get('getdata', 'Rombel::getData');
        $routes->get('getmapel', 'Rombel::getMapel');
        $routes->get('getmapping/(:num)', 'Rombel::getMapping/$1');
        $routes->get('getwalas', 'Rombel::getWalas');
        $routes->get('edit/(:num)', 'Rombel::edit/$1');
        $routes->post('add', 'Rombel::add');
        $routes->post('copypembelajaran', 'Rombel::copyPembelajaran');
        $routes->post('addmapping', 'Rombel::saveMapping');
        $routes->post('update', 'Rombel::update');
        $routes->delete('delete/(:num)', 'Rombel::delete/$1');
        $routes->delete('deletemapping/(:num)', 'Rombel::deleteMapping/$1');
        $routes->post('addanggota', 'Rombel::addanggota');
        $routes->get('getanggota/(:num)', 'Rombel::getAnggota/$1');
        $routes->delete('deleteanggota/(:num)', 'Rombel::deleteAnggota/$1');
    });
    $routes->group('ekstrakulikuler', function ($routes) {
        $routes->get('/', 'Ekstrakulikuler::index');
        $routes->get('getdata', 'Ekstrakulikuler::getData');
        $routes->get('getsiswa', 'Ekstrakulikuler::getSiswa');
        $routes->get('edit/(:num)', 'Ekstrakulikuler::edit/$1');
        $routes->post('add', 'Ekstrakulikuler::add');
        $routes->post('addanggota', 'Ekstrakulikuler::addanggota');
        $routes->get('getanggota/(:num)', 'Ekstrakulikuler::getAnggota/$1');
        $routes->post('update', 'Ekstrakulikuler::update');
        $routes->delete('delete/(:num)', 'Ekstrakulikuler::delete/$1');
        $routes->delete('deleteanggota/(:num)', 'Ekstrakulikuler::deleteAnggota/$1');
    });
});
$routes->group('siswa', ['filter' => 'role:admin'], function ($routes) {
    $routes->get('/', 'Siswa::index');
    $routes->get('qrcode', 'Siswa::generateQrCode');
    $routes->get('getdata', 'Siswa::getData');
    $routes->get('getsiswa', 'Siswa::getSiswa');
    $routes->get('getsiswarombel/(:num)', 'Siswa::getSiswaRombel/$1');
    $routes->get('getrombel', 'Siswa::getRombel');
    $routes->get('getrombelpeminatan', 'Siswa::getrombelPeminatan');
    $routes->get('edit/(:num)', 'Siswa::edit/$1');
    $routes->post('add', 'Siswa::add');
    $routes->post('update', 'Siswa::update');
    $routes->delete('delete/(:num)', 'Siswa::delete/$1');
    $routes->post('import', 'Siswa::importViaAjax');
    $routes->post('uploadfoto', 'Siswa::uploadFoto');
    $routes->get('detail/(:num)', 'Siswa::indexProfil/$1');
    $routes->post('updateprofil', 'Siswa::updateprofil');
});

$routes->group('auth', function ($routes) {
    $routes->get('login', 'Auth::login');
    $routes->get('register', 'Auth::register');
    $routes->get('logout', 'Auth::logout');
    $routes->post('dologin', 'Auth::yologin');
});

$routes->group('penilaian', ['filter' => 'role:admin,guru'], function ($routes) {
    $routes->group('akhir', function ($routes) {
        $routes->get('/', 'Penilaian::index');
        $routes->get('getpembelajaran', 'Penilaian::getPembelajaran');
        $routes->get('getsiswa/(:num)/(:num)', 'Penilaian::getSiswa/$1/$2');
        $routes->get('getcapaian/(:num)', 'Penilaian::getCapaian/$1');
        $routes->get('gettujuan/(:num)', 'Penilaian::getTujuan/$1');
        $routes->post('save', 'Penilaian::savePenilaian');
        $routes->post('savecapaian', 'Penilaian::saveCapaian');
        $routes->post('resetcapaian', 'Penilaian::resetCapaian');
    });
    $routes->group('eskul', function ($routes) {
        $routes->get('/', 'PenilaianEskul::index');
        $routes->get('getpenilaian/(:num)', 'PenilaianEskul::getPenilaian/$1');
        $routes->post('update', 'PenilaianEskul::update');
        $routes->delete('delete/(:num)', 'Tujuan::delete/$1');
    });
    $routes->group('absensi', function ($routes) {
        $routes->get('/', 'Absensi::index');
        $routes->get('getpenilaian/(:num)', 'PenilaianEskul::getPenilaian/$1');
        $routes->get('getdata', 'Absensi::getData');
        $routes->get('getsiswa/(:num)', 'Absensi::getSiswa/$1');
        $routes->post('simpan', 'Absensi::simpanAbsensi');
        $routes->post('simpancatatan', 'Absensi::simpanCatatan');
        $routes->delete('delete/(:num)', 'Tujuan::delete/$1');
    });
    $routes->group('leger', function ($routes) {
        $routes->get('/', 'Penilaian::indexLeger');
        $routes->get('getleger/(:num)', 'Penilaian::getLegerSiswa/$1');
        $routes->get('getrombel', 'Penilaian::getRombel');
        $routes->get('exporexcel/(:num)', 'Penilaian::exporExcel/$1');
    });
});
$routes->group('projek', ['filter' => 'role:admin,koordinator'], function ($routes) {
    $routes->group('koordinator', function ($routes) {
        $routes->get('/', 'Projek::indexKoordinator');
        $routes->get('getrombel', 'Projek::getRombel');
        $routes->post('save', 'Projek::saveKoordinator');
    });
    $routes->group('perencanaan', function ($routes) {
        $routes->get('/', 'Projek::index');
        $routes->get('getdata', 'Projek::getPerencanaan');
        $routes->get('getdimensi', 'Projek::getDimensi');
        $routes->get('getid/(:num)', 'Projek::getProjekId/$1');
        $routes->post('update', 'Projek::updateProjek');
        $routes->post('add', 'Projek::addProjek');
        $routes->delete('delete/(:num)', 'Projek::deleteProjek/$1');
    });
    $routes->group('penilaian', function ($routes) {
        $routes->get('/', 'ProjekPenilaian::index');
        $routes->get('getpenilaian/(:num)', 'ProjekPenilaian::getPenilaian/$1');
        $routes->get('getrombel', 'ProjekPenilaian::getRombel');
        $routes->post('save', 'ProjekPenilaian::savePenilaian');
    });
});
$routes->group('rapor', ['filter' => 'role:admin,walikelas'], function ($routes) {
    $routes->group('akhir', function ($routes) {
        $routes->get('/', 'Rapor::index');
        $routes->get('getdata', 'Rapor::getData');
        $routes->get('print/(:num)', 'Rapor::printRapor/$1');
        $routes->get('printsampul/(:num)', 'Rapor::printSampulRapor/$1');
        $routes->get('printprojek/(:num)', 'Rapor::printRaporProjek/$1');
        $routes->get('getrapor/(:num)', 'Rapor::getSiswa/$1');
    });
});
$routes->group('pengaturan', ['filter' => 'role:admin'], function ($routes) {
    $routes->group('sekolah', function ($routes) {
        $routes->get('/', 'Settings::index');
        $routes->get('getdata', 'Settings::getData');
        $routes->post('update', 'Settings::update');
    });
    $routes->group('patch', function ($routes) {
        $routes->get('/', 'PatchApp::index');
        $routes->post('update', 'PatchApp::update');
    });
});
