<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\GuruController;
use App\Http\Controllers\KelasController;
use App\Http\Controllers\MapelController;
use App\Http\Controllers\MateriController;
use App\Http\Controllers\MengajarController;
use App\Http\Controllers\SiswaController;
use App\Events\HelloEvent;

// Root route for the homepage
// Route::get('/send-event', function(){
//     broadcast(new HelloEvent());
//     return "testing";
// });

// Login routes
Route::get('login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('login', [AuthController::class, 'login']);
Route::post('logout', [AuthController::class, 'logout'])->name('logout');

Route::middleware('auth')->group(function () {
    Route::get('/', function () {
        return view('dashboard');
    })->name('home');

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

    Route::resource('siswa', SiswaController::class)->except(['create', 'edit']);
    Route::resource('guru', GuruController::class)->except(['create', 'edit', 'show']);

    Route::get('/mengajar/{id}', 'MengajarController@show')->name('mengajar.show');

    Route::get('kelas', [KelasController::class, 'index'])->name('kelas.index');
    Route::post('kelas', [KelasController::class, 'store'])->name('kelas.store');
    Route::put('kelas/{kelas}', [KelasController::class, 'update'])->name('kelas.update');
    Route::delete('kelas/{kelas}', [KelasController::class, 'destroy'])->name('kelas.destroy');

    Route::resource('mapel', MapelController::class)->except(['create', 'edit', 'show']);

    Route::get('materi', [MateriController::class, 'index'])->name('materi.index');
    Route::post('materi', [MateriController::class, 'store'])->name('materi.store');
    Route::put('materi/{id}', [MateriController::class, 'update'])->name('materi.update');
    Route::delete('materi/{id}', [MateriController::class, 'destroy'])->name('materi.destroy');

    Route::get('mengajar', [MengajarController::class, 'index'])->name('mengajar.index');
    Route::post('mengajar', [MengajarController::class, 'store'])->name('mengajar.store');
    Route::put('mengajar/{id}', [MengajarController::class, 'update'])->name('mengajar.update');
    Route::delete('update/{id}', [MengajarController::class, 'destroy'])->name('mengajar.destroy');
});
