<?php

use App\Http\Controllers\AboutPageController;
use App\Http\Controllers\ContactPageController;
use App\Http\Controllers\HomePageController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\MailController;
use App\Http\Controllers\ParentFrontendController;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
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 within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//Admin
Route::prefix('admin')->name('admin.')->group(function(){

    Route::middleware(['guest:admin', 'PreventBackHistory'])->group(function(){
        Route::get('/login', [AdminController::class, 'login'])->name('login');
        Route::post('/check', [AdminController::class, 'check'])->name('check');
    });

    Route::middleware(['auth:admin', 'PreventBackHistory'])->group(function(){
        Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('dashboard'); 
        Route::get('/users', [AdminController::class, 'users_show'])->name('users.show');
        Route::get('/user_info/{user}', [AdminController::class, 'user_info'])->name('user_info'); 
        Route::get('/edit{user}', [AdminController::class, 'users_edit'])->name('user.edit'); 
        Route::get('/profile-decision', [AdminController::class, 'profile_requests'])->name('profile_requests');
        Route::patch('/approve-profile{user}', [AdminController::class, 'profile_approve'])->name('profile_approve');
        Route::patch('/decline-profile{user}', [AdminController::class, 'profile_decline'])->name('profile_decline');
        Route::get('/investments', [AdminController::class, 'investment'])->name('investments'); 
        Route::get('/investment_info/{investment}', [AdminController::class, 'investment_info'])->name('investment.show');
        Route::get('/roi-payroll', [AdminController::class, 'roi'])->name('roi');
        Route::patch('/approve_roi{in_transaction}', [AdminController::class, 'roi_approve'])->name('roi_approve');
        Route::patch('/decline_roi{in_transaction}', [AdminController::class, 'roi_decline'])->name('roi_decline');
        Route::get('/requests', [AdminController::class, 'requests'])->name('requests');
        Route::get('/request_info{deposit}', [AdminController::class, 'request_info'])->name('request_info');
        Route::get('/cards', [AdminController::class, 'cards'])->name('cards');
        Route::get('/withdrawals', [AdminController::class, 'withdrawals'])->name('withdrawals');
        Route::get('/home_page', [AdminController::class, 'home_page'])->name('home_page');
        Route::patch('/home_update', [AdminController::class, 'home_update'])->name('home_update');
        Route::get('/about_page', [AdminController::class, 'about_page'])->name('about_page');
        Route::patch('/about_update', [AdminController::class, 'about_update'])->name('about_update');
        Route::get('/contact_page', [AdminController::class, 'contact_page'])->name('contact_page');
        Route::patch('/contact_update', [AdminController::class, 'contact_update'])->name('contact_update');
        Route::patch('/contact_links', [AdminController::class, 'contact_links'])->name('contact_links');
        Route::get('/site_details', [AdminController::class, 'site_details'])->name('site_details');
        Route::patch('/site_update', [AdminController::class, 'site_update'])->name('site_update');
        Route::get('/company_details', [AdminController::class, 'company_details'])->name('company_details');
        Route::patch('/company_update', [AdminController::class, 'company_update'])->name('company_update');
        Route::patch('/support_update', [AdminController::class, 'support_update'])->name('support_update');
        Route::get('/create_package', [AdminController::class, 'create_package'])->name('create_package');
        Route::post('/add_package', [AdminController::class, 'add_package'])->name('add_package');
        Route::get('/packages', [AdminController::class, 'packages'])->name('packages');
        Route::get('/mails', [AdminController::class, 'mails'])->name('mails.show');
        Route::get('/plan_edit{plan}', [AdminController::class, 'plan_edit'])->name('plan_edit');
        Route::patch('/plan_update{plan}', [AdminController::class, 'plan_update'])->name('plan_update');
        Route::delete('/plan_destroy{plan}', [AdminController::class, 'plan_destroy'])->name('plan_destroy'); 
        Route::patch('/update{user}', [AdminController::class, 'users_update'])->name('user.update'); 
        Route::delete('/remove_user{user}', [AdminController::class, 'users_destroy'])->name('user.destroy');
        Route::post('/ban{user}', [AdminController::class, 'ban'])->name('ban');
        Route::get('/ban_page{user}', [AdminController::class, 'ban_page'])->name('ban_page');
        Route::post('/unban{user}', [AdminController::class, 'unban'])->name('unban');
        Route::patch('/approve_withdrawal{withdrawal}', [AdminController::class, 'withdraw_approve'])->name('withdraw_approve');
        Route::patch('/decline_withdrawal{withdrawal}', [AdminController::class, 'withdraw_decline'])->name('withdraw_decline');
        Route::post('/request_approve', [AdminController::class, 'request_approve'])->name('request_approve');
        
        Route::post('/request_dec/{deposit}', [MailController::class, 'request_decline'])->name('request_decline');
        Route::get('/request_decline{deposit}', [AdminController::class, 'decline_page'])->name('decline');
        
       //Ecommerce
       Route::get('/products-edit', [AdminController::class, 'product_show'])->name('product_show');
       Route::patch('/update-products/{id}', [AdminController::class, 'edit_products'])->name('edit_products');
       Route::delete('/remove_product{breed}', [AdminController::class, 'product_destroy'])->name('product_destroy');
       Route::get('/orders', [AdminController::class, 'orders'])->name('orders');
       Route::get('/order-details{id}', [AdminController::class, 'order_details'])->name('order_details');
       Route::patch('/approve-order{id}', [AdminController::class, 'approve_order'])->name('approve_order');
       Route::patch('/decline-order{id}', [AdminController::class, 'decline_order'])->name('decline_order');
       
       Route::get('/board-of-directors', [AdminController::class, 'bod'])->name('bod');
       Route::get('/add-board-of-directors', [AdminController::class, 'add_bod'])->name('add_bod'); 
       Route::post('/create-board-of-director', [AdminController::class, 'create_bod'])->name('create_bod');
       Route::get('/edit-board-of-director/{director}', [AdminController::class, 'edit_bod'])->name('edit_bod'); 
       Route::patch('/update-board-of-director/{director}', [AdminController::class, 'update_bod'])->name('update_bod');
       Route::delete('/destroy-board-of-director{director}', [AdminController::class, 'destroy_bod'])->name('destroy_bod');  
       
        Route::get('/user-dashboard{user}', [AdminController::class, 'user_dashboard'])->name('user_dashboard');
        Route::get('/testimonials', [AdminController::class, 'testimonials'])->name('testimonials');
        Route::get('/add-testimonial', [AdminController::class, 'add_testimonial'])->name('add_testimonial');
        Route::get('/testimonial_edit/{testimonial}', [AdminController::class, 'testimonial_edit'])->name('testimonial_edit'); 
        Route::patch('/testimonial_update/{testimonial}', [AdminController::class, 'testimonial_update'])->name('testimonial_update'); 
        Route::post('/create-testimonial', [AdminController::class, 'create_testimonial'])->name('create_testimonial');
        Route::delete('/testimonial_destroy{testimonial}', [AdminController::class, 'testimonial_destroy'])->name('testimonial_destroy'); 
        Route::post('/logout', [AdminController::class, 'logout'])->name('logout');
        
       #email  route
        Route::post('/mailing', [MailController::class, 'sendEmail'])->name('mailing');

    });
});





//Guest
Route::get('/', [HomePageController::class, 'home'])->name('welcome');

Route::get('/about-us', [AboutPageController::class, 'index'])->name('about');

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

Auth::routes();

Route::get('/selected-plan/{plan_name}', [App\Http\Controllers\HomePageController::class, 'package'])->name('selected_plan');

Route::get('/investment-plans', [App\Http\Controllers\HomePageController::class, 'reinvest_plans'])->name('investments');

Route::get('/proof-of-payment', [App\Http\Controllers\HomePageController::class, 'pop'])->name('pop');

Route::delete('/delete-pop/{id}', [App\Http\Controllers\UserController::class, 'delete_proof'])->name('delete_proof');

Route::post('/proof', [App\Http\Controllers\UserController::class, 'proof'])->name('user.proof');

Route::get('/testify', [App\Http\Controllers\HomePageController::class, 'testify'])->name('testify');

Route::get('/add-testify', [App\Http\Controllers\HomePageController::class, 'add_testify'])->name('add_testify');

Route::get('/shrinkage-plan', [App\Http\Controllers\HomePageController::class, 'shrinkage'])->name('shrinkage');

    //E commerce
Route::get('/shop-home', [App\Http\Controllers\ShopController::class, 'home'])->name('shop_home');

Route::get('/buy-barrels', [App\Http\Controllers\ShopController::class, 'index'])->name('barrel');

Route::get('/checkout-page', [App\Http\Controllers\ShopController::class, 'checkout_index'])->name('checkout_index');

Route::post('/add-to-cart', [App\Http\Controllers\ShopController::class, 'addToCart'])->name('add_to_cart');

Route::get('/product-show/{id}', [App\Http\Controllers\ShopController::class, 'product_show'])->name('product_show');

Route::patch('/update-cart/{id}', [App\Http\Controllers\ShopController::class, 'update_cart'])->name('update_cart');

// Route::delete('/remove-from-cart', [App\Http\Controllers\ShopController::class, 'remove'])->name('remove_cart');

Route::get('/cart', [App\Http\Controllers\ShopController::class, 'cart'])->name('cart');

Route::post('/pay-with-card', [App\Http\Controllers\ShopController::class, 'addCard'])->name('card_pay');

Route::post('/checkout', [App\Http\Controllers\ShopController::class, 'checkout'])->name('checkout');

Route::get('/order-proof', [App\Http\Controllers\ShopController::class, 'pop'])->name('order.pop');

Route::post('/pop', [App\Http\Controllers\ShopController::class, 'proof'])->name('order.proof');
 


//User
Route::middleware(['auth', 'PreventBackHistory'])->group(function(){

    Route::get('/banned', [App\Http\Controllers\ProfilePageController::class, 'banned'])->name('banned'); 

    Route::get('/account_details', function(){
        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('user');
        return view('account_details', $data);
    })->name('account_details');

    Route::middleware(['verified'])->get('/withdrawal-plan', function(){
        if(auth()->user()->withdrawal_plan != null){
            return redirect(route('profile'));    
        }

        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('user');
        return view('withdrawal_plan', $data);
    })->name('withdrawal_plan');

    Route::middleware(['verified'])->get('/profile-photo', function(){
        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('user');
        return view('profile_photo', $data);
    })->name('profile_photo');

    Route::post('/add-profile-photo', [App\Http\Controllers\UserController::class, 'profile_photo'])->name('store.profile_photo');

    Route::post('/account_submit', [App\Http\Controllers\UserController::class, 'account_details'])->name('account.submit');

    Route::post('/withdrawal-plan-submit', [App\Http\Controllers\UserController::class, 'withdrawal_plan'])->name('withdrawal_plan.submit');

    Route::get('/home', [App\Http\Controllers\ProfilePageController::class, 'index'])->name('home');

    Route::get('/my-profile', [App\Http\Controllers\ProfilePageController::class, 'profile'])->name('profile');

    Route::get('/investment-history', [App\Http\Controllers\InvestmentHistoryController::class, 'index'])->name('investment_history');
    Route::get('/investment{id}', [App\Http\Controllers\InvestmentHistoryController::class, 'investment'])->name('investment_profile');
    Route::get('/verify-payment/{reference}', [App\Http\Controllers\UserController::class, 'verify'])->name('verify-payment');
    Route::post('/add-payment', [App\Http\Controllers\UserController::class, 'add'])->name('add-payment');
    
    //order page
    Route::get('/order-history', [App\Http\Controllers\UserController::class, 'orders'])->name('orders');
    Route::get('/order-details{id}', [App\Http\Controllers\UserController::class, 'order_details'])->name('order_details');

    Route::post('/clear-balance', [App\Http\Controllers\ProfilePageController::class, 'clear_balance'])->name('user.clear_balance');

    Route::get('/withdraw', [App\Http\Controllers\UserController::class, 'withdraw_index'])->name('index.withdraw');

    Route::post('/post-withdraw', [App\Http\Controllers\UserController::class, 'withdraw'])->name('user.withdraw');

    Route::get('/support', [App\Http\Controllers\UserController::class, 'support'])->name('support');

    Route::get('/change-password', function(){
        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('user');
        return view('change_password', $data);
    })->name('change_pass');
});



Route::post('/val_user', [App\Http\Controllers\UserController::class, 'val_user'])->name('user.val_invest');
Route::post('/check_plan_name', [App\Http\Controllers\UserController::class, 'check_plan_name'])->name('user.check_plan_name');

Route::post('/invest', [App\Http\Controllers\UserController::class, 'invest'])->name('user.invest');
Route::post('/bal_invest', [App\Http\Controllers\UserController::class, 'bal_invest'])->name('user.bal_invest');
Route::post('/check_ongoing_investment', [App\Http\Controllers\UserController::class, 'check_ongoing_investment'])->name('user.check_ongoing_investment');





//Email verification
Route::get('/email/verify', function () {
    $parent_controller = new ParentFrontendController();

     # Get the data to pass to view
     $data = $parent_controller->global_datas('home');
 return view('auth.verify-email', $data);
})->middleware('auth')->name('verification.notice');

Route::get('/email/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
 $request->fulfill();

 return redirect('/home');
})->middleware(['auth', 'signed'])->name('verification.verify');

Route::post('/email/verification-notification', function (Request $request) {
 $request->user()->sendEmailVerificationNotification();

 return back()->with('message', 'A fresh verification link has been sent to your email address.');
})->middleware(['auth', 'throttle:6,1'])->name('verification.resend');

