<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\OffreController;
use App\Http\Controllers\EtudiantController;
use App\Http\Controllers\DegreeController;
use App\Http\Controllers\AdminController;
use Barryvdh\DomPDF\Facade\Pdf;
use App\Models\User;

/*
|--------------------------------------------------------------------------
| 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('welcome');
});

Route::get('/', function () {
    return view('welcome');
})->name('welcome');

Route::group(['middleware' => ['auth', ]], function () {
    Route::get('/etudiants', [EtudiantController::class, 'index'])->name('etudiants.index');
    Route::get('/etudiants/showOffres/{id}', [EtudiantController::class, 'showOffres'])->name('etudiants.show-offres');
    Route::get('/etudiants/index', [EtudiantController::class, 'index'])->name('etudiants.offres.index');
    Route::get('/etudiants/profile', [EtudiantController::class, 'showProfil'])->name('etudiants.profile');
    Route::get('/etudiants/editProfile', [EtudiantController::class, 'editProfile'])->name('etudiants.editProfile');
    Route::post('/etudiants/updateProfile', [EtudiantController::class, 'updateProfile'])->name('etudiants.updateProfile');

    Route::get('/degrees/create', [DegreeController::class, 'create'])->name('alumnis.createDegree');
    Route::post('/degrees/store', [DegreeController::class, 'store'])->name('degrees.store');
    Route::get('/degrees', [DegreeController::class, 'index'])->name('alumnis.degree');
    Route::get('/degrees/{degree}', [DegreeController::class, 'edit'])->name('alumnis.updateDegree');
    Route::put('/degrees/{degree}', [DegreeController::class, 'update'])->name('update');
    Route::delete('/degrees/{degree}', [DegreeController::class, 'destroy'])->name('destroy');
    Route::get('/alumni/{id}/export-pdf', function ($id) { $user = User::with('degrees')->findOrFail($id);$pdf = Pdf::loadView('admin.alumni_pdf', compact('user'))->setPaper('a4', 'portrait');return $pdf->download('details_alumni_' . $id . '.pdf');})->name('alumni.export.pdf');

}
);

Route::group(['middleware' => ['auth',]], function () {
    Route::get('/admin/index', [AdminController::class, 'index'])->name('admin.index');
    Route::get('/admin/offres', [AdminController::class, 'Offres'])->name('admin.offres');
    Route::get('/admin/offres/showOffres/{id}', [AdminController::class, 'showOffres'])->name('admin.show-offres');
    Route::get('/admin/offres/create', [AdminController::class, 'createOffre'])->name('admin.offres.create');
    Route::post('/admin/offres/store', [AdminController::class, 'storeOffre'])->name('admin.store-offres');
    Route::get('/admin/offres/publisher/{id}', [AdminController::class, 'publisherOffre'])->name('admin.publisher-offres');
    Route::get('/admin/offres/stop/{id}', [AdminController::class, 'stopOffre'])->name('admin.stop-offres');
    Route::get('/admin/alumnis', [AdminController::class, 'showInscriptions'])->name('show-Inscriptions');
    Route::get('/admin/alumnis/{id}', [AdminController::class, 'showDetailsInscriptions'])->name('show-Details-Inscriptions');
    Route::get('/admin/alumnis/{id}/accept', [AdminController::class, 'acceptInscription'])->name('accept-Inscription');
    Route::get('/admin/showAlumnis', [AdminController::class, 'showAlumnis'])->name('admin.show-alumnis');
    Route::get('/admin/showEtudiant', [AdminController::class, 'showEtudiant'])->name('admin.show-etudiant');
    Route::get('/admin/showDetailsAlumnis/{id}', [AdminController::class, 'showDetailsAlumnis'])->name('admin.show-details-alumnis');
    Route::get('/admin/showDetailsEtudiant', [AdminController::class, 'showDetailsEtudiant'])->name('admin.show-details-etudiant');
    Route::post('/admin/alumnis/{id}/reject', [AdminController::class, 'rejectInscription'])->name('reject-Inscription');
    Route::get('/admin/offres/edite/{id}', [AdminController::class, 'editeOffre'])->name('admin.edite-offres');
    Route::post('/admin/offres/update/{id}', [AdminController::class, 'updateOffre'])->name('admin.update-offres');
    Route::get('/admin/offres/delete/{id}', [AdminController::class, 'deleteOffre'])->name('admin.delete-offres');
    Route::get('/admin/type-offres', [AdminController::class, 'TypeOffres'])->name('admin.type-offres');             
    Route::get('/admin/type-offres2', [AdminController::class, 'TypeOffres2'])->name('admin.type-offres2');             
    Route::get('/admin/type-offres/create', [AdminController::class, 'createTypeOffres'])->name('admin.type-offres.create');
    Route::get('/admin/type-offres/create2', [AdminController::class, 'createTypeOffres2'])->name('admin.type-offres.create2');
    Route::post('/admin/type-offres/store', [AdminController::class, 'storeTypeOffres'])->name('admin.store-type-offres');
    Route::post('/admin/create-offres', [AdminController::class, 'storeTypeOffres2'])->name('admin.store-type-offres2');
    Route::get('/admin/type-offres/edite/{id}', [AdminController::class, 'editeTypeOffres'])->name('admin.edite-type-offres');
    Route::post('/admin/type-offres/update/{id}', [AdminController::class, 'updateTypeOffres'])->name('admin.update-type-offres');
    Route::get('/admin/type-offres/delete/{id}', [AdminController::class, 'deleteTypeOffres'])->name('admin.delete-type-offres');
    Route::get('/admin/domaines', [AdminController::class, 'domaines'])->name('admin.domaines');
    Route::get('/admin/domaines/create', [AdminController::class, 'createDomaines'])->name('admin.domaines.create');
    Route::post('/admin/domaines/store', [AdminController::class, 'storeDomaines'])->name('admin.store-domaines');
    Route::get('/admin/domaines/edite/{id}', [AdminController::class, 'editeDomaines'])->name('admin.edite-domaines');
    Route::post('/admin/domaines/update/{id}', [AdminController::class, 'updateDomaines'])->name('admin.update-domaines');
    Route::get('/admin/domaines/delete/{id}', [AdminController::class, 'deleteDomaines'])->name('admin.delete-domaines');
    Route::get('/admin/domaines2', [AdminController::class, 'domaines2'])->name('admin.domaines2');
    Route::get('/admin/domaines/create2', [AdminController::class, 'createDomaines2'])->name('admin.domaines.create2');
    Route::post('/admin/domaines/store2', [AdminController::class, 'storeDomaines2'])->name('admin.store-domaines2');
}
);

Route::get('/offer-published', function () { return view('emails.offer_published');});

Route::get('/login', [AuthController::class, 'showLoginForm'])->name('show-login');

Route::post('/login', [AuthController::class, 'login'])->name('login');

Route::get('/register', [AuthController::class, 'showRegisterForm'])->name('show-register');

Route::post('/register', [AuthController::class, 'register'])->name('register');

Route::get('/register', [AuthController::class, 'createFilieres'])->name('register.form');


Route::get('/logout', [AuthController::class, 'logout'])->name('logout');

Route::get('/modification/{token}', [AuthController::class, 'edit'])->name('modification.page');


Route::post('/modification/{id}', [AuthController::class, 'update'])->name('modification.update');
