<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\BlogController;
use App\Http\Controllers\PhotoController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\PrestasiController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\Admin\AkunController;
use App\Http\Controllers\Admin\EkskulController;
use App\Http\Controllers\EkskulPublicController;
use App\Http\Controllers\AppController; // ← WAJIB DITAMBAH
use App\Http\Controllers\VideoController;
use Illuminate\Support\Facades\Route;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

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

Route::get('/berita', [AppController::class, 'berita']);

Route::get('/detail/{slug}', [AppController::class, 'detail']);

// Route::get('/foto', function () {
//     return view('foto.foto');
// });

Route::get('/foto-kegiatan', [PhotoController::class, 'foto'])
    ->name('foto.kegiatan');

Route::get('/video-lainnya', [VideoController::class, 'videoLainnya'])
    ->name('video.lainnya');

// frontend
Route::get('/profil', [ProfileController::class, 'index'])->name('profil');

// admin
Route::get('/admin/profil', [ProfileController::class, 'edit'])->middleware('auth');
Route::post('/admin/profil', [ProfileController::class, 'update'])->middleware('auth');

use App\Http\Controllers\ContactController;

Route::get('/kontak', [ContactController::class, 'index'])->name('kontak');
Route::post('/kontak/kirim', [ContactController::class, 'store'])->name('kontak.kirim');



Route::get('/login', [AuthController::class, 'index'])->name('login')->middleware('guest');
// Route::get('/login', [AuthController::class, 'index'])->name('login');
Route::post('/login', [AuthController::class, 'authenticate']);
// Route::post('/logout', [AuthController::class, 'logout']);
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

// ADMIN PROFIL
Route::get('/admin/profil', [ProfileController::class, 'edit'])
    ->name('admin.profil')
    ->middleware('auth');

Route::post('/admin/profil', [ProfileController::class, 'update'])
    ->name('admin.profil.update')
    ->middleware('auth');

// admin
Route::get('/admin/prestasi', [PrestasiController::class, 'index'])
    ->middleware('auth')
    ->name('prestasi.admin');

Route::post('/admin/prestasi/store', [PrestasiController::class, 'store'])->middleware('auth');
Route::post('/admin/prestasi/update/{id}', [PrestasiController::class, 'update'])->middleware('auth');
Route::post('/admin/prestasi/delete/{id}', [PrestasiController::class, 'destroy'])->middleware('auth');

Route::middleware(['auth', 'role:admin'])->group(function () {

    Route::get('/admin/akun', [AkunController::class, 'index'])
        ->name('admin.akun');

    Route::post('/admin/akun/update', [AkunController::class, 'update'])
        ->name('admin.akun.update');
});

Route::prefix('admin')->middleware('auth')->group(function () {
    Route::resource('hero', \App\Http\Controllers\Admin\HeroController::class);
});

// Route::middleware('auth')->prefix('admin')->group(function () {
//     Route::get('/ekskul', [EkskulController::class, 'index'])->name('admin.ekskul');
//     Route::post('/ekskul/store', [EkskulController::class, 'store']);
//     Route::post('/ekskul/delete/{id}', [EkskulController::class, 'destroy']);
// });
Route::prefix('admin')->name('admin.')->middleware(['auth'])->group(function () {
    Route::resource('ekskul', EkskulController::class);
});
Route::get('/ekskul', [App\Http\Controllers\Admin\EkskulController::class, 'index'])
    ->name('ekskul');

Route::get('/ekskul', [EkskulPublicController::class, 'index'])->name('ekskul.public');

// publik
Route::get('/prestasi', [PrestasiController::class, 'publik'])->name('prestasi');


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

Route::get('/blog', [BlogController::class, 'index'])->name('blog')->middleware('auth');
Route::get('/blog/create', [BlogController::class, 'create'])->name('blog.create')->middleware('auth');
Route::post('/blog/store', [BlogController::class, 'store'])->name('blog.store')->middleware('auth');
Route::get('/blog/edit/{id}', [BlogController::class, 'edit'])->name('blog.edit')->middleware('auth');
Route::post('/blog/update/{id}', [BlogController::class, 'update'])->name('blog.update')->middleware('auth');
Route::post('/blog/destroy/{id}', [BlogController::class, 'destroy'])->name('blog.destroy')->middleware('auth');

Route::get('/photo', [photoController::class, 'index'])->name('photo')->middleware('auth');
Route::post('/photo/store', [photoController::class, 'store'])->name('photo.store')->middleware('auth');
Route::post('/photo/update/{id}', [photoController::class, 'update'])->name('photo.update')->middleware('auth');
Route::post('/photo/destroy/{id}', [photoController::class, 'destroy'])->name('photo.destroy')->middleware('auth');

Route::get('/video', [VideoController::class, 'index'])->name('video')->middleware('auth');
Route::post('/video/store', [videoController::class, 'store'])->name('video.store')->middleware('auth');
Route::post('/video/update/{id}', [videoController::class, 'update'])->name('video.update')->middleware('auth');
Route::post('/video/destroy/{id}', [videoController::class, 'destroy'])->name('video.destroy')->middleware('auth');
