<?php

use App\Http\Controllers\InventarisController;
use App\Http\Controllers\JadwalController;
use App\Http\Controllers\JadwalPerawatanController;
use App\Http\Controllers\JurnalController;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\PengajuanBarangController;
use App\Http\Controllers\RekapanController;
use App\Http\Controllers\SerahTerimaController;
use App\Http\Controllers\TemplateController;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

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

// ROLE ROUTING
// - ADMIN
// - GURU
// - SISWA
Route::middleware(['auth'])->group(function () {
    Route::get('/home', function () {
        $user = Auth::user();

        if (!$user) {
            return redirect('/');
        }

        return match ($user->role) {
            'admin' => redirect('/admin'),
            'guru' => redirect('/guru'),
            'siswa' => redirect('/siswa'),
            default => redirect('/')->with('error', 'Role tidak dikenali'),
        };
    })->name('home');
});


// JADWAL ROUTING
// - ADMIN
Route::get('/jadwal/download-pdf/{jurusan}', [JadwalController::class, 'downloadJadwalPDF'])->name('jadwal.download-pdf');
Route::get('/jadwal/view-pdf/{jurusan}', [JadwalController::class, 'viewJadwalPDF'])->name('jadwal.view-pdf');

// REKAPAN ROUTING
// - GURU
// - SISWA
Route::get('/rekapan/guru-download-pdf/{jurusan}', [RekapanController::class, 'downloadGuruPDF'])->name('rekapan-guru.download-pdf');
Route::get('/rekapan/guru-view-pdf/{jurusan}', [RekapanController::class, 'viewGuruPDF'])->name('rekapan-guru.view-pdf');

Route::get('/rekapan/siswa-download-pdf/{jurusan}', [RekapanController::class, 'downloadSiswaPDF'])->name('rekapan-siswa.download-pdf');
Route::get('/rekapan/siswa-view-pdf/{jurusan}', [RekapanController::class, 'viewSiswaPDF'])->name('rekapan-siswa.view-pdf');

// JURNAL ROUTING
// - ADMIN
Route::get('/jurnal/download-pdf/{jurusan}', [JurnalController::class, 'downloadJurnalPDF'])->name('jurnal.download-pdf');
Route::get('/jurnal/view-pdf/{jurusan}', [JurnalController::class, 'viewJurnalPDF'])->name('jurnal.view-pdf');

// INVENTARIS ROUTING
// - ADMIN
Route::get('/inventaris/download-pdf', [InventarisController::class, 'downloadInventarisPDF'])->name('inventaris.download-pdf');
Route::get('/inventaris/view-pdf', [InventarisController::class, 'viewInventarisPDF'])->name('inventaris.view-pdf');

// SERAH TERIMA ROUTING
// - ADMIN
Route::get('/serah-terima/bulk-print/{ids}', [SerahTerimaController::class, 'bulkSerahTerimaPrint'])->name('serah-terima.bulk-print');

// PENGAJUAN BARANG ROUTING
// - ADMIN
Route::get('/pengajuan-barang/bulk-print/{ids}', [PengajuanBarangController::class, 'bulkPengajuanPrint'])->name('pengajuan-barang.bulk-print');

// JADWAL PERAWATAN ROUTING
// - ADMIN
Route::get('/jadwal-perawatan/download-pdf/{tahun}/{semester}/{type}/{kepemilikan}', [JadwalPerawatanController::class, 'downloadJadwalPerawatanPDF'])->name('jadwal-perawatan.download-pdf');
Route::get('/jadwal-perawatan/view-pdf/{tahun}/{semester}/{type}/{kepemilikan}', [JadwalPerawatanController::class, 'viewJadwalPerawatanPDF'])->name('jadwal-perawatan.view-pdf');

// TEMPLATE ROUTING
// - ADMIN
Route::get('/download-user-template', [TemplateController::class, 'downloadUserTemplate'])->name('download.user.template');
