<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\BukuController;
use App\Http\Controllers\SiswaController;
use App\Http\Controllers\PeminjamanController;
use App\Http\Controllers\LaporanBukuController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// HALAMAN DEPAN (BEBAS DIAKSES)
Route::get('/', function () {
    return view('welcome');
});

// ===============================
// SEMUA ROUTE DI BAWAH INI WAJIB LOGIN
// ===============================
Route::middleware(['auth'])->group(function () {

    // HOME
    Route::get('/home', [HomeController::class, 'index'])
        ->name('home');

    // ===============================
    // BUKU
    // ===============================
    Route::resource('buku', BukuController::class);

    // ===============================
    // SISWA
    // ===============================
    Route::resource('siswa', SiswaController::class);

    Route::post('/siswa/{id}/daftar', [SiswaController::class, 'daftar'])
        ->name('siswa.daftar');

    Route::post('/siswa/{id}/nonaktif', [SiswaController::class, 'nonaktif'])
        ->name('siswa.nonaktif');

    Route::post('/siswa/{id}/aktifkan', [SiswaController::class, 'aktifkan'])
        ->name('siswa.aktifkan');
Route::get('/siswa/{id}/cetak-kta', [SiswaController::class, 'cetakKTA'])
    ->name('siswa.cetakKTA');

    // ===============================
    // PEMINJAMAN
    // ===============================
    Route::get('/peminjaman', [PeminjamanController::class, 'index'])
        ->name('peminjaman.index');

    // CREATE (WAJIB PER ID BUKU)
    Route::get('/peminjaman/create/{buku_id}', [PeminjamanController::class, 'create'])
        ->name('peminjaman.create');

    // STORE
    Route::post('/peminjaman/store', [PeminjamanController::class, 'store'])
        ->name('peminjaman.store');

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

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

    // PENGEMBALIAN
    Route::put('/peminjaman/{id}/kembali', [PeminjamanController::class, 'pengembalian'])
        ->name('peminjaman.kembali');
        Route::get('/peminjaman/{id}/invoice', [PeminjamanController::class, 'cetakInvoicePeminjaman'])
    ->name('peminjaman.invoice');

Route::get('/peminjaman/{id}/invoice-pengembalian', [PeminjamanController::class, 'cetakInvoicePengembalian'])
    ->name('peminjaman.invoicePengembalian');

    Route::get('/laporan/buku', [LaporanBukuController::class, 'index'])
    ->name('laporan.buku');

Route::get('/laporan/buku/detail', [LaporanBukuController::class, 'detail'])
    ->name('laporan.buku.detail');

Route::get('/laporan/buku/cetak', [LaporanBukuController::class, 'cetakPdf'])
    ->name('laporan.buku.cetak');


});
