<?php

use App\Http\Controllers\Frontend\ContactController;
use App\Http\Controllers\Frontend\HomeController;
use App\Http\Controllers\Frontend\User\AccountController;
use App\Http\Controllers\Frontend\User\DashboardController;
use App\Http\Controllers\Frontend\User\ProfileController;
use App\Http\Controllers\Frontend\Auth\ConfirmAccountController;

/*
 * Frontend Controllers
 * All route names are prefixed with 'frontend.'.
 */
//Route::get('/', [HomeController::class, 'index'])->name('index');
//if(!Auth::check()){
//    //dd('hi');
Route::get('/', [HomeController::class, 'index'])->name('index');
//}else{
//
////dd('ho');
//    Route::get('/', [HomeController::class, 'home'])->name('index')->middleware('auth');
//}
Route::get('contact', [HomeController::class, 'contact'])->name('contact');
Route::get('plans_pricing', [HomeController::class, 'plans_pricing'])->name('plans_pricing');
Route::get('about_us', [HomeController::class, 'about_us'])->name('about_us');
Route::post('contact/send', [ContactController::class, 'send'])->name('contact.send');
// privacy policy page
Route::get('privacy', [HomeController::class, 'privacy'])->name('privacy');
// TOS policy page
Route::get('tos', [HomeController::class, 'tos'])->name('tos');


//@TODO Remove/hide prior to deployment
//Route::get('clipart/updatethumb', [\App\Http\Controllers\Frontend\Graphics\ClipartController::class, 'updateThumbs']);
/*
 * These frontend controllers require the user to be logged in
 * All route names are prefixed with 'frontend.'
 * These routes can not be hit if the password is expired
 */
Route::group(['middleware' => ['auth', 'password_expires']], function () {
    Route::group(['namespace' => 'User', 'as' => 'user.'], function () {
        // User Dashboard Specific
        Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');

        // User Account Specific
        Route::get('account', [AccountController::class, 'index'])->name('account');

        // User Profile Specific
        Route::patch('profile/update', [ProfileController::class, 'update'])->name('profile.update');

        Route::get('profile/{uuid}', [ProfileController::class, 'view'])->name('profile.view');

        Route::get('searchprofileforselect2', [ProfileController::class, 'searchforselect2']);


        Route::get('searchprofileforselect2private', [ProfileController::class, 'searchforselect2private']);

        // first login
//        Route::get('firstlogin', [AccountController::class, 'showFirstLoginForm'])->name('firstlogin');
//        Route::post('firstlogin', [AccountController::class, 'acceptFirstLoginPost'])->name('firstlogin.post');
//
//        Route::post('firstpay', [AccountController::class, 'showFirstPayForm'])->name('firstpay');
//        Route::post('firstsubscription', [AccountController::class, 'processFirstPayment'])->name('firstsubscription');

        // change plans
        // show the change plan form, which includes the payment method if none exists
//        Route::get('changeplan', [AccountController::class, 'showChangePlanForm'])->name('changeplan');
        Route::get('newplan', [AccountController::class, 'showNewPlanForm'])->name('newplan');
        // get the plan details when selected
        Route::post('getplandetails', [AccountController::class, 'getPlanDetails'])->name('getplandetails');
        // update the plan, eventually ending up at the Stripe checkout portal
        Route::post('newplan', [AccountController::class, 'acceptNewPlanForm'])->name('newplan.post');

        // URLs for success, failure from the checkout portal
        Route::get('changeplansuccess', [AccountController::class, 'showChangePlanFormSuccess'])->name('changeplansuccess');
        Route::get('changeplanfailure', [AccountController::class, 'showChangePlanFormFailure'])->name('changeplanfailure');

        // redirect to billing portal
        Route::get('plansettings', function (\Illuminate\Http\Request $request) {
            return $request->user()->redirectToBillingPortal(route('frontend.user.account'));
        })->name('plansettings');;

        // DEPRECATED
        // change payment method
        // show the update payment method form
//        Route::get('changepaymentmethod', [AccountController::class, 'showChangePaymentMethodForm'])->name('changepaymentmethod');
//        // update the payment method
//        Route::post('changepaymentmethod', [AccountController::class, 'acceptChangePaymentMethodForm'])->name('changepaymentmethod.post');

        // cancel plan. Sorry to see you go!
        // show the cancel plan form
        Route::get('cancelplan', [AccountController::class, 'showCancelPlanForm'])->name('cancelplan');
        // perform the cancel
        Route::post('cancelplan', [AccountController::class, 'acceptCancelPlanForm'])->name('cancelplan.post');

        // maybe deprecated?
        //  Route::post('updatesubscription', [AccountController::class, 'processPayment'])->name('updatesubscription');

        Route::post('makeCollaborator', [AccountController::class, 'makeCollaborator'])->name('makeCollaborator');
        Route::post('removeCollaborator', [AccountController::class, 'removeCollaborator'])->name('removeCollaborator');

        // Stripe stuff: get promo code details
        Route::get('checkpromocode', [AccountController::class, 'validatePromocode'])->name('checkpromocode');
    });
});

///*
// * error routes
// */
//
//Route::group(['namespace' => 'Error', 'as' => 'error.'], function () {
//    // first login
//    Route::get('stripeerror', [AccountController::class, 'showFirstLoginForm'])->name('firstlogin');
//
//});
