<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Http\Controllers\PotensiController;
use App\Http\Controllers\AuthController;

// ==========================================
// 1. ROUTE FRONTEND (HALAMAN UTAMA DESA)
// ==========================================
Route::get('/', function () {
    // Ambil data untuk ditampilkan di halaman depan
    $potensis = \App\Models\Potensi::latest()->take(3)->get();
    return view('home', compact('potensis'));
});



// ==========================================
// 2. ROUTE AUTHENTICATION (LOGIN & LOGOUT MANUAL)
// ==========================================
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login')->middleware('guest');
Route::post('/login', [AuthController::class, 'login']);
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');


// ==========================================
// 3. ROUTE ADMIN PANEL (Profil Desa Custom)
// ==========================================
Route::prefix('admin')->middleware(['auth'])->name('admin.')->group(function () {

    // Halaman Dashboard Utama
    Route::get('/', function () {
        $potensiCount = \App\Models\Potensi::count();
        return view('admin.dashboard', compact('potensiCount'));
    })->name('dashboard');

    // Potensi Desa
    Route::resource('potensi', PotensiController::class)->except(['show']);



});
