<?php

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\DashboardController;
use App\Http\Controllers\BeneficiaryController;
use App\Http\Controllers\MonitoringController;
use App\Http\Controllers\MapController;
use App\Http\Controllers\ImportController;
use App\Http\Controllers\ExportController;
use App\Http\Controllers\DocumentationController;
use App\Http\Controllers\UserController;

Route::get('/login', [App\Http\Controllers\Auth\LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [App\Http\Controllers\Auth\LoginController::class, 'login']);
Route::post('/logout', [App\Http\Controllers\Auth\LoginController::class, 'logout'])->name('logout');

Route::middleware(['auth'])->group(function () {
    Route::get('/test-ui', function () {
        return view('test-ui');
    });

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

    Route::get('/map', [MapController::class, 'index'])->name('map');

    Route::prefix('beneficiaries')->group(function () {
        Route::get('/', [BeneficiaryController::class, 'index'])->name('beneficiaries.index');
        Route::get('/create', [BeneficiaryController::class, 'create'])->name('beneficiaries.create');
        Route::post('/store', [BeneficiaryController::class, 'store'])->name('beneficiaries.store');
        Route::get('/{id}/edit', [BeneficiaryController::class, 'edit'])->name('beneficiaries.edit');
        Route::put('/{id}', [BeneficiaryController::class, 'update'])->name('beneficiaries.update');
        Route::get('/{id}', [BeneficiaryController::class, 'show'])->name('beneficiaries.show');
    });

    Route::prefix('import')->group(function () {
        Route::get('/', [ImportController::class, 'index'])->name('import.index');
        Route::post('/store', [ImportController::class, 'store'])->name('import.store');
    });

    Route::prefix('export')->group(function () {
        Route::get('/beneficiaries', [ExportController::class, 'beneficiaries'])->name('export.beneficiaries');
        Route::get('/beneficiary-pdf/{id}', [ExportController::class, 'pdf'])->name('export.pdf');
    });

    Route::prefix('monitoring')->group(function () {
        Route::get('/create/{beneficiary_id}', [MonitoringController::class, 'create'])->name('monitoring.create');
        Route::post('/store', [MonitoringController::class, 'store'])->name('monitoring.store');
    });

    Route::get('/documentation', [DocumentationController::class, 'index'])->name('documentation.index');

    // User Management & Profile
    Route::get('/profile', [UserController::class, 'profile'])->name('users.profile');
    Route::put('/profile', [UserController::class, 'updateProfile'])->name('users.profile.update');

    Route::middleware(['role:Admin'])->group(function () {
        Route::resource('users', UserController::class)->except(['show']);
    });
});
Route::get('/install-hosting', function() {
    Artisan::call('storage:link');
    Artisan::call('config:cache');
    Artisan::call('route:cache');
    Artisan::call('view:cache');
    return "Instalasi Berhasil: Storage link created and Cache cleared!";
});