<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PendaftaranController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\PendaftaranAdminController;
use App\Http\Controllers\Admin\PanitiaController;
use App\Http\Controllers\Admin\PendaftaranController as AdminPendaftaranController;
use App\Http\Controllers\Admin\GrafikPendaftaranController;

/*
|--------------------------------------------------------------------------
| HALAMAN DEPAN
|--------------------------------------------------------------------------
*/
/**Route::get('/', function () {
    return view('welcome');
})->name('home');
*/

use App\Http\Controllers\LandingController;

Route::get('/', [LandingController::class, 'index']);



/*
|--------------------------------------------------------------------------
| PENDAFTARAN SPMB
|--------------------------------------------------------------------------
*/
Route::get('/daftar', [PendaftaranController::class, 'create'])
    ->name('daftar');

Route::post('/daftar/preview', [PendaftaranController::class, 'preview'])
    ->name('daftar.preview');

Route::post('/daftar/simpan', [PendaftaranController::class, 'store'])
    ->name('daftar.store');

Route::get('/daftar/bukti/{id}', [PendaftaranController::class, 'bukti'])
    ->name('bukti.pendaftaran');

/*
|--------------------------------------------------------------------------
| AUTH LOGIN
|--------------------------------------------------------------------------
*/
Route::get('/login', [AuthController::class, 'formLogin'])
    ->name('login');

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

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

/*
|--------------------------------------------------------------------------
| ADMIN AREA
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:admin'])
    ->prefix('admin')
    ->name('admin.')
    ->group(function () {

        // Dashboard Admin
        Route::get('/dashboard', [DashboardController::class, 'index'])
            ->name('dashboard');

        // CRUD Pendaftaran
        Route::get('/pendaftaran', [PendaftaranAdminController::class, 'index'])
            ->name('pendaftaran.index');

        Route::get('/pendaftaran/{id}/edit', [PendaftaranAdminController::class, 'edit'])
            ->name('pendaftaran.edit');

        Route::put('/pendaftaran/{id}', [PendaftaranAdminController::class, 'update'])
            ->name('pendaftaran.update');

        Route::delete('/pendaftaran/{id}', [PendaftaranAdminController::class, 'destroy'])
            ->name('pendaftaran.destroy');

       
    });



// Halaman khusus grafik pendaftaran per jurusan
Route::middleware(['auth','is_admin'])->group(function () {
    Route::get('/admin/grafik-pendaftaran', [AdminPendaftaranController::class, 'index'])
        ->name('admin.grafik-pendaftaran');
});


    //ROUTE EXPORT CSV
Route::get('/admin/pendaftaran/export/csv',
    [PendaftaranAdminController::class, 'exportCsv']
)->name('admin.pendaftaran.export.csv');


Route::middleware(['auth','is_admin'])->group(function () {
    Route::get('/admin/grafik-pendaftaran', [GrafikPendaftaranController::class, 'index'])
        ->name('admin.grafik-pendaftaran');
});