<?php

use CodeIgniter\Router\RouteCollection;

$routes->get('/', 'Dashboard::index');
$routes->get('dashboard', 'Dashboard::index');

$routes->get('login', 'Auth::login');
$routes->post('login', 'Auth::process');
$routes->get('logout', 'Auth::logout');


$routes->group('master', ['filter' => 'auth'], function ($routes) {

    // ===== SITE =====
    $routes->get('site', 'Master\Site::index');
    $routes->get('site/data', 'Master\Site::data');
    $routes->get('site/create', 'Master\Site::create');
    $routes->post('site/store', 'Master\Site::store');
    $routes->get('site/edit/(:num)', 'Master\Site::edit/$1');
    $routes->post('site/update/(:num)', 'Master\Site::update/$1');
    $routes->get('site/delete/(:num)', 'Master\Site::delete/$1');

    // ===== KELAS =====
    $routes->get('kelas', 'Master\Kelas::index');
    $routes->get('kelas/data', 'Master\Kelas::data');
    $routes->get('kelas/create', 'Master\Kelas::create');
    $routes->post('kelas/store', 'Master\Kelas::store');
    $routes->get('kelas/edit/(:num)', 'Master\Kelas::edit/$1');
    $routes->post('kelas/update/(:num)', 'Master\Kelas::update/$1');

    // ===== JURUSAN / PROGRAM =====
    $routes->get('major', 'Master\Major::index');
    $routes->get('major/data', 'Master\Major::data');
    $routes->get('major/create', 'Master\Major::create');
    $routes->post('major/store', 'Master\Major::store');
    $routes->get('major/edit/(:num)', 'Master\Major::edit/$1');
    $routes->post('major/update/(:num)', 'Master\Major::update/$1');
    $routes->get('major/delete/(:num)', 'Master\Major::delete/$1');

    // ===== SUBJECT / MAPEL =====
    $routes->get('subject', 'Master\Subject::index');
    $routes->get('subject/data', 'Master\Subject::data');
    $routes->get('subject/create', 'Master\Subject::create');
    $routes->post('subject/store', 'Master\Subject::store');
    $routes->get('subject/edit/(:num)', 'Master\Subject::edit/$1');
    $routes->post('subject/update/(:num)', 'Master\Subject::update/$1');
    $routes->get('subject/delete/(:num)', 'Master\Subject::delete/$1');

    // ===== JADWAL =====
    $routes->get('jadwal', 'Master\Jadwal::index');
    $routes->get('jadwal/data', 'Master\Jadwal::data');
    $routes->post('jadwal/store', 'Master\Jadwal::store');
    $routes->post('jadwal/delete', 'Master\Jadwal::delete');
});

$routes->group('ppdb', ['namespace' => 'App\Controllers\PPDB'], function ($routes) {

    // LOGIN PPDB
    $routes->get('login', 'Auth::login');
    $routes->post('login', 'Auth::process');
    $routes->get('logout', 'Auth::logout');

    // REGISTRASI
    $routes->get('/', 'Ppdb::index');
    $routes->post('store', 'Ppdb::store');

    // DASHBOARD
    $routes->get('dashboard', 'Dashboard::index', ['filter' => 'ppdb_auth']);

    // 🔐 GANTI PASSWORD (INI SAJA)
    $routes->get('account/password', 'Account::password', ['filter' => 'ppdb_auth']);
    $routes->post('account/password', 'Account::updatePassword', ['filter' => 'ppdb_auth']);
});



$routes->group('security', ['filter' => 'auth'], function ($routes) {
    $routes->get('users', 'Security\User::index');
    $routes->get('role', 'Security\Role::index');
    $routes->get('permission', 'Security\Permission::index');
    $routes->get('log', 'Security\Log::index');
});

$routes->get('email-test', function () {
    $email = \Config\Services::email();
    $email->setTo('dimanacro@gmail.com');
    $email->setSubject('TEST EMAIL PPDB');
    $email->setMessage('<b>Email PPDB berhasil!</b>');

    return $email->send() ? 'EMAIL OK' : $email->printDebugger();
});

$routes->group('elearning', ['filter' => 'auth'], function ($routes) {

    $routes->get('materi', 'Elearning\Materi::index');
    $routes->get('materi/filter', 'Elearning\Materi::filter');
    $routes->get('materi/data', 'Elearning\Materi::data');
    $routes->get('materi/create', 'Elearning\Materi::create');
    $routes->post('materi/store', 'Elearning\Materi::store');
    $routes->get('elearning/materi/view/(:num)', 'Elearning\Materi::view/$1');


    $routes->get('exam', 'Elearning\Exam::index');
    $routes->get('grade', 'Elearning\Grade::index');

});

$routes->group('elearning', ['filter' => 'auth'], function ($routes) {

    // ===== MATERI =====
    $routes->get('materi', 'Elearning\Materi::index');
    $routes->get('materi/view/(:num)', 'Elearning\Materi::view/$1');

    // ===== TUGAS =====
    $routes->get('task', 'Elearning\Task::index');
    $routes->get('task/view/(:num)', 'Elearning\Task::view/$1');
    $routes->post('task/submit/(:num)', 'Elearning\Task::submit/$1');

    // ===== EXAM =====
    $routes->get('exam', 'Elearning\Exam::index');
    $routes->get('grade', 'Elearning\Grade::index');

    $routes->get('elearning/task/(:num)', 'Elearning\Task::view/$1');
    $routes->post('elearning/task/submit/(:num)', 'Elearning\Task::submit/$1');

});


