<?php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Backend\AdminsController;
use App\Http\Controllers\Backend\Auth\ForgotPasswordController;
use App\Http\Controllers\Backend\Auth\LoginController;
use App\Http\Controllers\GenerateDataMasterController;
use App\Http\Controllers\Backend\DashboardController;
use App\Http\Controllers\Backend\RolesController;
use App\Http\Controllers\Backend\MenuRoleController;

Auth::routes();



Route::group(['prefix' => 'admin', 'as' => 'admin.'], function () {
    // Login Routes.
    Route::post('/login/submit', [LoginController::class, 'login'])->name('login.submit');
    Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
    // Logout Routes.
    Route::post('/logout/submit', [LoginController::class, 'logout'])->name('logout.submit');
});




/**
 * Admin routes
 */
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'middleware' => ['auth:admin', 'menu']], function () {
    Route::resource('admins', AdminsController::class);
    Route::resource('roles', RolesController::class);
    Route::get('/admin', [DashboardController::class, 'index'])->name('dashboard');
})->middleware(['auth:admin']);

Route::middleware(['auth:admin', 'menu'])->group(function () {
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard.index');
    //Menu Role
    Route::get('/auth/menu-tree/{id}', [MenuRoleController::class, 'index'])->name('auth.menurole.index');
    Route::post('/auth/menu-tree/submit', [MenuRoleController::class, 'saveMenu'])->name('auth.menurole.submit');
});