<?php
use App\Http\Controllers\{ActivityController,AttendanceController,AuditLogController,AuthController,DashboardController,GenericModuleController,LetterController,MemberController,NewsController,OrganizationUnitController,PopupController,ProgramController,PublicSiteController,RantingController};
use Illuminate\Support\Facades\Route;

Route::get('/', [PublicSiteController::class,'home'])->name('home');
Route::get('/berita', [PublicSiteController::class,'news'])->name('public.news');
Route::get('/berita/{slug}', [PublicSiteController::class,'article'])->name('public.article');
Route::get('/agenda', [PublicSiteController::class,'agenda'])->name('public.agenda');
Route::get('/verifikasi/{token}', [PublicSiteController::class,'verify'])->name('verify.letter');
Route::get('/presensi/{token}', [AttendanceController::class,'publicForm'])->name('attendance.public');
Route::post('/presensi/{token}', [AttendanceController::class,'submit'])->name('attendance.submit');
Route::get('/ranting/{slug}', [PublicSiteController::class,'ranting'])->name('public.ranting');

Route::middleware('guest')->group(function(){
    Route::get('/login',[AuthController::class,'showLogin'])->name('login');
    Route::post('/login',[AuthController::class,'login'])->name('login.post');
});

Route::middleware(['auth','audit'])->group(function(){
    Route::post('/logout',[AuthController::class,'logout'])->name('logout');
    Route::get('/dashboard',[DashboardController::class,'index'])->name('dashboard');

    Route::get('/organisasi/unit',[OrganizationUnitController::class,'index'])->name('units.index');
    Route::post('/organisasi/unit',[OrganizationUnitController::class,'store'])->name('units.store');
    Route::patch('/organisasi/unit/{organization}',[OrganizationUnitController::class,'update'])->name('units.update');
    Route::get('/organisasi/ranting',[RantingController::class,'index'])->name('rantings.index');
    Route::post('/organisasi/ranting',[RantingController::class,'store'])->name('rantings.store');
    Route::patch('/organisasi/ranting/{organization}',[RantingController::class,'update'])->name('rantings.update');

    Route::get('/organisasi/pengurus',[MemberController::class,'index'])->name('members.index');
    Route::post('/organisasi/pengurus',[MemberController::class,'store'])->name('members.store');
    Route::get('/organisasi/pengurus/{member}/whatsapp',[MemberController::class,'whatsapp'])->name('members.whatsapp');

    Route::get('/program',[ProgramController::class,'index'])->name('programs.index');
    Route::post('/program',[ProgramController::class,'store'])->name('programs.store');
    Route::get('/kegiatan',[ActivityController::class,'index'])->name('activities.index');
    Route::post('/kegiatan',[ActivityController::class,'store'])->name('activities.store');

    Route::get('/presensi',[AttendanceController::class,'index'])->name('attendance.index');
    Route::post('/presensi',[AttendanceController::class,'store'])->name('attendance.store');
    Route::get('/presensi/{session}/rekap',[AttendanceController::class,'entries'])->name('attendance.entries');
    Route::post('/presensi/{session}/toggle',[AttendanceController::class,'toggle'])->name('attendance.toggle');

    Route::get('/administrasi/surat',[LetterController::class,'index'])->name('letters.index');
    Route::post('/administrasi/surat',[LetterController::class,'store'])->name('letters.store');
    Route::get('/publikasi/berita',[NewsController::class,'index'])->name('news.index');
    Route::post('/publikasi/berita',[NewsController::class,'store'])->name('news.store');
    Route::get('/publikasi/popup',[PopupController::class,'index'])->name('popups.index');
    Route::post('/publikasi/popup',[PopupController::class,'store'])->name('popups.store');
    Route::post('/publikasi/popup/{popup}/toggle',[PopupController::class,'toggle'])->name('popups.toggle');
    Route::get('/sistem/audit-log',[AuditLogController::class,'index'])->name('audit.index');

    Route::get('/modul/{module}',[GenericModuleController::class,'show'])->name('module.show');
});

// URL publik Banom/Lembaga berbasis slash, contoh: /fatayat, /lazisnu, /lpmaarif.
// Diletakkan paling bawah agar tidak mengambil route sistem seperti /login, /berita, /agenda, dll.
Route::get('/{slug}', [PublicSiteController::class,'unit'])->where('slug','[A-Za-z0-9\-]+')->name('public.unit');
