<?php

use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\VisitorController;

use App\Http\Controllers\CertificatesController;
use App\Http\Controllers\TrainingController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\StudentsRegisterController;
use App\Http\Controllers\AdmitController;
use App\Http\Controllers\TransactionController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\LandingPageController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
    return view('collegelanding');
});

Route::get('/qms', function () {
    return view('index');
});

Route::get('/pdfviewer', [LandingPageController::class, 'viewPdfPage']);

Route::get('/reprintcert/{refno}', [CertificatesController::class, 'reprintCert']);

Route::get('/Paybillpayment', [TransactionController::class, 'index'])->name('paybillpayment');

Route::get('/PaymentUpdate', [TransactionController::class, 'checkAndUpdatePayments'])->name('paymentconfirmation');

Route::get('/SendReceipt', [TransactionController::class, 'getEnrollmentData']);

Route::get('/reprint-receipt/{studentId}', [TransactionController::class, 'reprintReceipt'])->name('reprintReceipt');
Route::post('/send-receipt/{studentId}', [TransactionController::class, 'sendReceipt'])->name('sendReceipt');


Route::get('/StudentRegistration', [StudentsRegisterController::class, 'StudentSelfRegister'])->name('studentRegister');
Route::post('/StudentRegistrationEnrolment', [StudentsRegisterController::class, 'SelfEnrolmentTab'])->name('storeEnrolmentForm');
Route::get('/payment', [StudentsRegisterController::class, 'anotherFunction'])->name('payment');

Route::get('/update-expired-status', [CertificatesController::class, 'updateExpiredStatus']);

Route::post('/settle-bill/{id}', [StudentsRegisterController::class, 'settleBill'])->name('settleBill');



Route::get('/homepage', function () {
    return view('staticpages.home');
}); 



Route::post('/submit-form', [VisitorController::class, 'store'])->name('submit-form');
Route::any('/updateSelfpass', [UserController::class, 'changeUsersPassword'])->name('changeUsersPassword');



//Route::get('/visitors', function () {    return view('visitors');});

Route::get('/visitors', [VisitorController::class, 'showVisitors']);

Route::get('/ViewCert', [CertificatesController::class, 'MakeCertificate']);
Route::get('/ViewNewCert', [CertificatesController::class, 'MakeCertificatenew']);

Route::get('/ViewMiniCert/{serialNo}', [CertificatesController::class, 'MakeminiCertificatenew'])->name('mini.certificate');//cards


Route::get('/ViewReceipt', [CertificatesController::class, 'receiptbook']);
Route::get('/ViewNewReceipt', [CertificatesController::class, 'newreceiptbook']);


Route::get('/GetCert', [CertificatesController::class, 'getcertificate'])->name('GetCert');
Route::post('/GetCerts', [CertificatesController::class, 'getcert'])->name('generate-cert');

Route::any('/ReprintCertificate', [LandingPageController::class, 'regenerateCert'])->name('regenerateCert');


Route::get('/send-certification/{idnumbers}', [CertificatesController::class, 'Emailcert']);

//Route::POST('resend-cert/{nationalId}', [CertificatesController::class, 'resendCertificate'])->name('resend-cert');
Route::post('/resend-cert/{cert_serial}', [CertificatesController::class, 'resendCertificate'])->name('resend-cert');

//send walkathon invitation
Route::get('/Walkathoncampaign', [NotificationController::class, 'Walkathoninvitation']);

Auth::routes();
Route::middleware(['user-role:admin'])->group(function()
//Route::group(['prefix' => 'training', 'auth','user-role:admin'], function() {
{
    Route::group(['prefix' => 'training'], function() {
    Route::get('/', [TrainingController::class, 'home'])->name('hometraining');
    Route::get('/StudentsTable', [TrainingController::class, 'Studenttable'])->name('Studentstable');
    Route::post('/students/register', [TrainingController::class, 'registerstudent'])->name('register.student');


    Route::get('/StudentsEnrolments', [StudentsRegisterController::class, 'EnrolledStudentstable'])->name('Studentenrolments');
    Route::get('/WeeklyStudentsEnrolments', [StudentsRegisterController::class, 'WeeklyEnrolledStudentstable'])->name('weeklyStudentenrolments');
    Route::get('/monthlyStudentsEnrolments', [StudentsRegisterController::class, 'MonthlyEnrolledStudentstable'])->name('monthlyStudentenrolments');
    Route::post('/students/{id}/confirm-manual-payment', [StudentsRegisterController::class, 'confirmManualPayment'])->name('confirmManualPayment');


    Route::get('/students/{id}/edit', [App\Http\Controllers\StudentsRegisterController::class, 'editenrolment'])->name('students.edit');
    Route::post('/students/{id}/update', [App\Http\Controllers\StudentsRegisterController::class, 'updateenrolment'])->name('students.update');


    //admit students
    route::post('/admit-student', [AdmitController::class, 'admitStudent'])->name('admitStudent');
    //list of admissions done
    Route::get('/admissions', [AdmitController::class, 'showAdmissions'])->name('admissions.index');
    Route::get('/Weeklyadmissions', [AdmitController::class, 'showweeklyAdmissions'])->name('admissions.weekly');
    Route::get('/monthlyadmissions', [AdmitController::class, 'showMonthlyAdmissions'])->name('admissions.monthly');
    Route::get('/FilterAdmissions', [AdmitController::class, 'filteradmition'])->name('filteradmission');//filter admittions per month


    Route::get('/RegisterStation', [TrainingController::class, 'registerTrainingStations'])->name('registerTrainingStations');
    Route::post('/register-training-station', [TrainingController::class, 'savetrainingstation'])->name('register.training.station');
    Route::patch('/stations/{id}/toggle-status', [TrainingController::class, 'toggleStatus'])->name('stations.toggleStatus');

    Route::get('/RegisterCourses', [TrainingController::class, 'registerCourses'])->name('registerCourses');
    Route::post('/register-Courses', [TrainingController::class, 'saveCourses'])->name('register.Courses');

    Route::get('/EnrolmentTab', [TrainingController::class, 'StudentEnrolmenttab'])->name('StudentEnrolmenttab');


    Route::get('/CertifiedStudents', [CertificatesController::class, 'CertificiedStudents'])->name('CertificiedStudents');
    Route::POST('/RegisterCertifiedStudent', [CertificatesController::class, 'registerCertifiedStudent'])->name('registerCertifiedStudent');

    // Route::get('/forms', [DashboardOneController::class, 'form'])->name('dashoneform');
    Route::get('/Table', [TrainingController::class, 'table'])->name('dashonetable');
    // Route::get('/blank', [TrainingController::class, 'blank'])->name('dashoneblank');
    // Route::get('/formtable', [DashboardOneController::class, 'formtable'])->name('dashoneformtable');

    Route::get('/MakeUpdateRequest', [TrainingController::class, 'updatepaymentrequest'])->name('paymentupdate');
    Route::post('/update-payment', [TransactionController::class, 'postPaymentUpdate'])->name('post.payment.update');

    Route::get('/Sendtextsms', [TrainingController::class, 'sendtextsms'])->name('sendtextsms');
    Route::post('/sendsmsMessage', [TrainingController::class, 'completetextsms'])->name('completetextsms');



    Route::get('/ViewTrainers', [TrainingController::class, 'TrainersView'])->name('training.dashboard');
    Route::post('/register/trainer', [TrainingController::class, 'storeTrainer'])->name('register.trainer');

    //reports
    Route::get('/RevenueSummary', [TrainingController::class, 'trainingstationsrevenue'])->name('trainingstationsrevenue');
    //finance data
    Route::get('/PaymentData', [TrainingController::class, 'mpesaEnrollments'])->name('mpesaEnrollments');


    // user managements
    Route::get('/Listusers', [UserController::class, 'index'])->name('users.index');
    Route::post('/update-user', [UserController::class, 'updateUser'])->name('update_user');
    Route::any('/users/{user}/change-password', [UserController::class, 'changePassword'])->name('change_password');
    Route::post('/Userregister', [UserController::class, 'registerUser'])->name('registerUser');



});
});
//}


    


//Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

// Route User
Route::middleware(['auth','user-role:user'])->group(function()
{
    Route::get("/home",[HomeController::class, 'userHome'])->name("home");
});
// Route Editor
Route::middleware(['auth','user-role:editor'])->group(function()
{
    Route::get("/editor/home",[HomeController::class, 'editorHome'])->name("editor.home");
});
// Route Admin
Route::middleware(['auth','user-role:training'])->group(function()
{
    Route::get("/admin/home",[HomeController::class, 'adminHome'])->name("admin.home");
});
