<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LoanApplicationController;
use App\Http\Controllers\Admin\AdminController;

/*
|--------------------------------------------------------------------------
| 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('/', function () {
//     return view('welcome');
// });


Route::view('/', 'pages.index');
Route::view('/dashboard', 'pages.dashboard');
Route::view('/deposit-money', 'pages.deposit-money');
Route::view('/withdraw-money', 'pages.withdraw-money');
Route::view('/send-money', 'pages.send-money');
Route::view('/request-money', 'pages.request-money');
Route::view('/apply-loan', 'pages.apply-loan');
Route::view('/transactions', 'pages.transactions');
Route::view('/login', 'pages.log-in');
Route::view('/register', 'pages.register');
Route::view('/get-started', 'pages.get-started');
// Route::view('/loan-application-details', 'pages.loan-application-details');

// Route::view('/loan-application-details', 'pages.loan-application-details');

//Route::view('/my-account', 'pages.my-account');

Route::view('/view-application', 'pages.view-application');

Route::view('/help-center', 'pages.help-center');

Route::view('/loan-status', 'pages.loan-status')->name('loan-status');

Route::post('/loan-verify-number', [LoanApplicationController::class, 'loanverifynumber']);

Route::post('/verify-loan-otp', [LoanApplicationController::class, 'verifyloanOtp']);





Route::post('/verify-user', [LoanApplicationController::class, 'verifyUser']);

Route::post('/verify-otp', [LoanApplicationController::class, 'verifyOtp']);




// Route::get('/loan-logout', function () {

//     session()->forget('loan_user_id');

//     return redirect('/loan-status');

// });




Route::middleware('auth')->group(function () {

   Route::get('/my-account', [LoanApplicationController::class, 'myAccount']);

    Route::post('/save-step-2', [LoanApplicationController::class, 'saveStep2']);

    Route::post('/save-step-3', [LoanApplicationController::class, 'saveStep3']);
    
    Route::post('/save-step-4', [LoanApplicationController::class, 'saveStep4']);
    
    Route::post('/submit-application', [LoanApplicationController::class, 'submitApplication']);
    Route::get('/loan-logout', [LoanApplicationController::class, 'logout']);
    Route::get('/loan-details-fetch/{id}', [LoanApplicationController::class, 'loanDetailsfetch'])
        ->name('loan.details.fetch');
    Route::get('/loan-details-fetch/{id}/download', [LoanApplicationController::class, 'loanDetailsDownload'])
        ->name('loan.details.download');
});


Route::get('/admin', [AdminController::class, 'login'])
    ->name('admin.login');

Route::post('/admin/login', [AdminController::class, 'loginSubmit'])
    ->name('admin.login.submit');
    
Route::middleware(['auth', 'admin'])
    ->prefix('admin')
    ->group(function () {

       
        Route::get('/dashboard',
            [AdminController::class, 'dashboard'])
            ->name('admin.dashboard');

        Route::get('/user-loans/{id}',
            [AdminController::class, 'userLoans'])
            ->name('admin.user.loans');

        Route::post('/logout',
            [AdminController::class, 'logout'])
            ->name('admin.logout');
            
        Route::get('/loan-details/{id}',
    [AdminController::class, 'loanDetails'])
    ->name('admin.loan.details');

Route::get('/loan-details/{id}/download',
    [AdminController::class, 'loanDetailsDownload'])
    ->name('admin.loan.details.download');

Route::post('/loan-status-update/{id}',
    [AdminController::class, 'loanStatusUpdate'])
    ->name('admin.loan.status.update');
});
