<?php

use App\Http\Controllers\AdminPromotionController;
use App\Http\Controllers\AdminUserController;
use App\Http\Controllers\AttributeController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\CountryController;
use App\Http\Controllers\CronController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\DataTableController;
use App\Http\Controllers\FileController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\IngredientController;
use App\Http\Controllers\LeadController;
use App\Http\Controllers\LeadTypeController;
use App\Http\Controllers\MembershipController;
use App\Http\Controllers\ModalController;
use App\Http\Controllers\Pay\PayPalController;
use App\Http\Controllers\PaymentCreditController;
use App\Http\Controllers\PaymentInvoiceController;
use App\Http\Controllers\PaymentMethodController;
use App\Http\Controllers\PaymentPayCreditController;
use App\Http\Controllers\PaymentReminderController;
use App\Http\Controllers\PaymentTemplatesController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\SalesController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\ShippingController;
use App\Http\Controllers\SitesController;
use App\Http\Controllers\Stats\SalesController as StatsSalesController;
use App\Http\Controllers\SyS\AdminToolsController;
use App\Http\Controllers\TranslationController;
use App\Http\Controllers\TranslationFileController;
use App\Http\Controllers\User\CheckoutController;
use App\Http\Controllers\User\CustomerController as UserCustomerController;
use App\Http\Controllers\User\MyOrderController;
use App\Http\Controllers\User\OrderController;
use App\Http\Controllers\User\PaymentController as UserPaymentController;
use App\Http\Controllers\User\PromotionController as UserPromotionController;
use App\Http\Controllers\User\SalesController as UserSalesController;
use App\Http\Controllers\User\ShopController as UserShopController;
use App\Http\Controllers\User\TeamController;
use App\Http\Controllers\UserDataController;
use App\Http\Controllers\UserDeleteController;
use App\Http\Controllers\UserLevelController;
use App\Http\Controllers\UserUpdateEmailController;
use App\Http\Controllers\UserUpdatePasswordController;
use App\Http\Controllers\Web\PromotionController;
use App\Http\Controllers\Web\RegisterController;
use App\Http\Controllers\Web\ShopController;
use App\Http\Controllers\WizardController;
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!
|
*/
Route::get('/product/image/{slug}', function($slug = null)
{
    if($image = \App\Models\ProductImage::where('slug', $slug)->first()){
        $path = storage_path('app/public').$image->getImagePath();
        if (file_exists($path)) {
            return Response::file($path);
        }
    }
})->name('product_image');


Route::get('/response/file/{disk}/{slug}', function($disk = null, $slug = null)
{
    $path = \Storage::disk($disk)->path(str_replace('_', '/', $slug));
    if (file_exists($path)) {
        return Response::file($path);
    }
})->name('response_file');

Route::get('/iq/image/{slug}', function($slug = null)
{
    if($image = \App\Models\IqImage::where('slug', $slug)->first()){
        $path = storage_path('app/public').'/images/iq_images/'.$image->filename;
        if (file_exists($path)) {
            return Response::file($path);
        }
    }

})->name('iq_image');

Route::get('locale/{locale}', function ($locale) {
    \Session::put('locale', $locale);
    if(Auth::check()){
        $user = Auth::user();
        $user->lang = $locale;
        $user->save();
    }
    return redirect()->back();
})->name('locale');

Route::domain(config('app.domain'))->group(function () {

    Auth::routes();
    Route::get('/logout', function(){
        Auth::logout();
        return Redirect::to('login');
    })->name('logout');


    Route::post('/user_register', [RegisterController::class, 'register'])->name('user_register');
    Route::post('/user_register_again', [RegisterController::class, 'registerAgain'])->name('user_register_again');

    Route::get('/register/consent', [RegisterController::class, 'showConsentPage'])->name('register.consent');
    Route::post('/register/consent', [RegisterController::class, 'acceptConsent'])->name('register.consent.accept');
    Route::get('/register', [RegisterController::class, 'showRegistrationForm'])->name('register.form');


    Route::get('/user_register/finish', [RegisterController::class, 'finish'])->name('user_register_finish');
    Route::get('/register/verify/{confirmationCode}', [RegisterController::class, 'verify'])->name('register_verify');
    Route::get('/reg/{member_id?}', [RegisterController::class, 'member'])->name('register_user_member');

    Route::get('/status/register', [HomeController::class, 'statusRegister'])->name('status_register');
    Route::get('/status/verify', [HomeController::class, 'statusVerify'])->name('status_verify');
    Route::get('/status/error', [HomeController::class, 'statusError'])->name('status_error');
    Route::get('/status/not/found', [HomeController::class, 'notFound'])->name('not_found');

    Route::post('/loading/modal', [HomeController::class, 'loadingModal'])->name('loading_modal');

    Route::post('/user/check/mail', [HomeController::class, 'checkMail'])->name('user_check_mail');

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

    Route::get('/cron/jobs/action/{action}/{key}', [CronController::class, 'action'])->name('cron_jobs_action');

    Route::get('/user/update_email_confirm/{token}', [UserUpdateEmailController::class, 'activateMail'])->name('user_update_email_confirm');

    /* AUTH */
    Route::group(['middleware' => ['auth']], function() {
        Route::get('/user_blocked', [HomeController::class, 'blocked'])->name('user_blocked');
        Route::get('/wizard-create', [WizardController::class, 'create'])->name('wizard_create');
        Route::get('/wizard-register', [WizardController::class, 'register'])->name('wizard_register');

        Route::post('/wizard/store/create/{step?}', [WizardController::class, 'storeCreate'])->name('wizard_store_create');
        Route::post('/wizard/store/register/{step?}', [WizardController::class, 'storeRegister'])->name('wizard_store_register');

        Route::get('/wizard/payment', [WizardController::class, 'payment'])->name('wizard_payment');
        Route::post('/wizard/store/payment/{step?}', [WizardController::class, 'storePayment'])->name('wizard_store_payment');

        Route::get('/wizard/delete/file/{id}/{relation}', [WizardController::class, 'delete'])->name('wizard_delete_file');

        Route::get('/storage/file/{id}/{disk}/{do?}', [FileController::class, 'show'])->name('storage_file');
    });

    /* AUTH user*/
    Route::group(['middleware' => ['auth:user']], function() {

        Route::get('storage/{type?}/{file?}', function($type = null, $file = null)
        {
            if($type == 'xls'){
                $path = storage_path("app/export/");
                $filename = $file.'.xls';
            }

            if (file_exists($path.$filename)) {
                return Response::download($path.$filename, $filename);
            }
        })->name('storage');

        Route::get('/home', [HomeController::class, 'show'])->name('home');
        Route::post('/modal/load', [ModalController::class, 'load'])->name('modal_load');

        Route::get('/user/edit', [UserDataController::class, 'userEdit'])->name('user_edit');
        Route::post('/user/edit', [UserDataController::class, 'userEditStore'])->name('user_edit');
        Route::post('/user/data/store', [UserDataController::class, 'userDataStore'])->name('user_data_store');

        Route::get('/user/profile', [UserDataController::class, 'userProfile'])->name('user_profile');
        Route::post('/user/profile', [UserDataController::class, 'userProfileStore'])->name('user_profile');
        Route::post('/user/profile/image/upload', [UserDataController::class, 'imageUpload'])->name('user_profile_image_upload');
        Route::get('/user/profile/image/delete/{image_id}', [UserDataController::class, 'imageDelete'])->name('user_profile_image_delete');
        
        Route::get('/user/update_password', [UserUpdatePasswordController::class, 'updatePassword'])->name('user_update_password');
        Route::post('/user/update_password', [UserUpdatePasswordController::class, 'updatePasswordStore'])->name('user_update_password');

        Route::get('/user/update_password_first', [UserUpdatePasswordController::class, 'updatePasswordFirst'])->name('user_update_password_first');
        Route::post('/user/update_password_first', [UserUpdatePasswordController::class, 'updatePasswordFirstStore'])->name('user_update_password_first');

        Route::get('/user/update_email', [UserUpdateEmailController::class, 'index'])->name('user_update_email');
        Route::post('/user/update_email', [UserUpdateEmailController::class, 'update'])->name('user_update_email');

        Route::get('/user/delete_account', [UserDeleteController::class, 'deleteAccount'])->name('user_delete_account');
        Route::post('/user/delete_account', [UserDeleteController::class, 'deleteAccountAction'])->name('user_delete_account');

        Route::post('/user/data/accepted/form', [UserDataController::class, 'userDataAcceptedForm'])->name('user_data_accepted_form');

        Route::get('/user/data/free', [UserDataController::class, 'userDataFree'])->name('user_data_free');
        Route::post('/user/data/free/form', [UserDataController::class, 'userDataFreeForm'])->name('user_data_free_form');


        //user Sales
        Route::get('/user/sales', [UserSalesController::class, 'orders'])->name('user_sales');
        Route::get('/user/sales/detail/{id}', [UserSalesController::class, 'orderDetail'])->name('user_sales_detail');
        Route::get('/user/sales/datatable', [UserSalesController::class, 'ordersDatatable'])->name('user_sales_datatable');

        //user team
        Route::get('/user/team/members', [TeamController::class, 'members'])->name('user_team_members');

        //user customers
        Route::get('/user/customers', [UserCustomerController::class, 'index'])->name('user_customers');
        Route::get('/user/customer/detail/{id}', [UserCustomerController::class, 'detail'])->name('user_customer_detail');
        Route::get('/user/customer/edit/{id}', [UserCustomerController::class, 'edit'])->name('user_customer_edit');
        Route::get('/user/customer/add/{id}/{step?}', [UserCustomerController::class, 'add'])->name('user_customer_add');
        Route::post('/user/customer/edit/{id}', [UserCustomerController::class, 'store'])->name('user_customer_edit');
        Route::get('/user/customer/datatable', [UserCustomerController::class, 'getCustomers'])->name('user_customer_datatable');

        //user order & do order
        Route::get('/user/myorders', [MyOrderController::class, 'index'])->name('user_myorders');
        Route::get('/user/myorder/datatable', [MyOrderController::class, 'datatable'])->name('user_myorder_datatable');
        Route::get('/user/myorder/detail/{id}', [MyOrderController::class, 'detail'])->name('user_myorder_detail');


        Route::get('/user/order/my/delivery/{for}/{id?}', [OrderController::class, 'delivery'])->name('user_order_my_delivery');
        Route::post('/user/order/my/delivery/{for}/{id?}', [OrderController::class, 'delivery'])->name('user_order_my_delivery');

        Route::get('/user/order/my/list/{for}/{id?}', [OrderController::class, 'list'])->name('user_order_my_list');
        Route::post('/user/order/my/list/{for}/{id?}', [OrderController::class, 'list'])->name('user_order_my_list');

        Route::post('/user/order/my/payment/{for}/{id?}', [OrderController::class, 'payment'])->name('user_order_my_payment');
        Route::get('/user/order/my/datatable', [OrderController::class, 'datatable'])->name('user_order_my_datatable');
        Route::post('/user/order/my/perform/request/', [OrderController::class, 'performRequest'])->name('user_order_my_perform_request');

        Route::get('/user/membership', [MembershipController::class, 'index'])->name('user_membership');
        Route::post('/user/membership/store/{action}', [MembershipController::class, 'storePayment'])->name('user_membership_store');


        //user shop
        Route::get('/user/shop', [UserShopController::class, 'index'])->name('user_shop');
        Route::post('/user/shop/store', [UserShopController::class, 'store'])->name('user_shop_store');
        Route::post('/user/shop/load', [UserShopController::class, 'load'])->name('user_shop_load');

        Route::get('/user/shop/translate', [UserShopController::class, 'translate'])->name('user_shop_translate');
        Route::post('/user/shop/translate/store', [UserShopController::class, 'translateStore'])->name('user_shop_tanslate_store');

        //user shop Sales
        Route::get('/user/sales/', [UserSalesController::class, 'index'])->name('user_sales');
        Route::get('/user/sales/detail/{id}', [UserSalesController::class, 'detail'])->name('user_sales_detail');
        Route::get('/user/sales/datatable', [UserSalesController::class, 'datatable'])->name('user_sales_datatable');


        Route::get('/user/payment/paycredit', [UserPaymentController::class, 'paycredit'])->name('user_payment_paycredit');
        Route::get('/user/payment/paycredit/datatable', [UserPaymentController::class, 'paycredit_datatable'])->name('user_payment_paycredit_datatable');

        Route::get('/user/payment/credit', [UserPaymentController::class, 'credit'])->name('user_payment_credit');
        Route::get('/user/payment/credit/datatable', [UserPaymentController::class, 'credit_datatable'])->name('user_payment_credit_datatable');

        Route::get('/user/payment/revenue', [UserPaymentController::class, 'revenue'])->name('user_payment_revenue');
        Route::post('/user/payment/revenue', [UserPaymentController::class, 'revenue'])->name('user_payment_revenue');

        //Route::get('/user/payment/credit/datatable', [UserPaymentController::class, 'credit_datatable'])->name('user_payment_credit_datatable');
        
        Route::get('/user/checkout/{identifier?}', [CheckoutController::class, 'checkout'])->name('user_checkout');
        Route::post('/user/checkout_store/{identifier?}', [CheckoutController::class, 'store'])->name('user_checkout_store');
        Route::get('/user/checkout_final/{payid}/{reference}/{identifier?}', [CheckoutController::class, 'final'])->name('user_checkout_final');

        Route::get('/user/promotion', [UserPromotionController::class, 'index'])->name('user_promotion');
        Route::get('/user/promotion/detail/{id}', [UserPromotionController::class, 'detail'])->name('user_promotion_detail');
        Route::post('/user/promotion/detail/{id}', [UserPromotionController::class, 'store'])->name('user_promotion_detail');
        Route::post('/user/promotion/load', [UserPromotionController::class, 'load'])->name('user_promotion_load');
        Route::get('/user/promotion/delete/{id}/{del?}', [UserPromotionController::class, 'delete'])->name('user_promotion_delete');

    });
    Route::group(['middleware' => ['copyreader']], function()
    {
        //products
        Route::get('/admin/product/show', [ProductController::class, 'index'])->name('admin_product_show');
        Route::post('/admin/product/store', [ProductController::class, 'store'])->name('admin_product_store');
        Route::get('/admin/product/edit/{id}', [ProductController::class, 'edit'])->name('admin_product_edit');
        Route::get('/admin/product/copy/{id}', [ProductController::class, 'copy'])->name('admin_product_copy');
        Route::get('/admin/product/delete/{id}/{do?}/{did?}', [ProductController::class, 'delete'])->name('admin_product_delete');
        //products images
        Route::post('/admin/product/image/upload', [ProductController::class, 'imageUpload'])->name('admin_product_image_upload');
        Route::get('/admin/product/image/delete/{image_id}/{product_id}', [ProductController::class, 'imageDelete'])->name('admin_product_image_delete');
        Route::get('/admin/product/image/attribute/{image_id}/{attr}/{val}', [ProductController::class, 'imageAttribute'])->name('admin_product_image_attribute');

        //products categories
        Route::get('/admin/product/categories', [CategoryController::class, 'index'])->name('admin_product_categories');
        Route::get('/admin/product/category/edit/{id}', [CategoryController::class, 'edit'])->name('admin_product_category_edit');
        Route::post('/admin/product/category/store', [CategoryController::class, 'store'])->name('admin_product_category_store');
        Route::get('/admin/product/category/delete/{id}', [CategoryController::class, 'delete'])->name('admin_product_category_delete');

        //products categories
        Route::get('/admin/product/ingredients', [IngredientController::class, 'index'])->name('admin_product_ingredients');
        Route::get('/admin/product/ingredient/edit/{id}', [IngredientController::class, 'edit'])->name('admin_product_ingredient_edit');
        Route::post('/admin/product/ingredient/store', [IngredientController::class, 'store'])->name('admin_product_ingredient_store');
        Route::get('/admin/product/ingredient/delete/{id}', [IngredientController::class, 'delete'])->name('admin_product_ingredient_delete');

        //products images
        Route::post('/admin/product/category/image/upload', [CategoryController::class, 'imageUpload'])->name('admin_product_category_image_upload');
        Route::get('/admin/product/category/image/delete{image_id}/{category_id}', [CategoryController::class, 'imageDelete'])->name('admin_product_category_image_delete');
        Route::get('/admin/product/category/image/attribute/{image_id}/{attr}/{val}', [CategoryController::class, 'imageAttribute'])->name('admin_product_category_image_attribute');

        //products attributes
        Route::get('/admin/product/attributes', [AttributeController::class, 'index'])->name('admin_product_attributes');
        Route::post('/admin/product/attribute/store', [AttributeController::class, 'store'])->name('admin_product_attribute_store');
        Route::get('/admin/product/attribute/delete/{attr}/{id}', [AttributeController::class, 'delete'])->name('admin_product_attribute_delete');
    });
    Route::group(['middleware' => ['admin']], function()
    {
        //translate
        Route::get('/admin/translate/all', [TranslationController::class, 'index'])->name('admin_translate_all');
        Route::get('/admin/translate/all/edit/{lang}/{from?}', [TranslationController::class, 'edit'])->name('admin_translate_all_edit');
        Route::post('/admin/translate/all/update/{lang}/{from?}', [TranslationController::class, 'update'])->name('admin_translate_all_update');

        Route::get('/admin/translate/file', [TranslationFileController::class, 'index'])->name('admin_translate_file');
        Route::get('/admin/translation/file/{file}/{language?}/{langsource?}/{show?}', [TranslationFileController::class, 'edit'])->name('admin_translate_file_edit');
        Route::post('/admin/translation/file/{file}/{language?}/{langsource?}/{show?}', [TranslationFileController::class, 'update'])->name('admin_translate_file_update');

        //site
        Route::get('/admin/sites/{site}', [SitesController::class, 'show'])->name('admin_sites');
        Route::post('/admin/sites/store/{site}', [SitesController::class, 'store'])->name('admin_sites_store');
        Route::post('/admin/sites/image/upload/{site}', [SitesController::class, 'imageUpload'])->name('admin_sites_image_upload');
        Route::get('/admin/sites/image/delete/{site}/{image_id}', [SitesController::class, 'imageDelete'])->name('admin_sites_image_delete');
        Route::get('/admin/sites/image/attribute/{site}/{image_id}/{attr}/{val}', [SitesController::class, 'imageAttribute'])->name('admin_sites_image_attribute');


        //Auswertungen products sales volume
        Route::get('/admin/stats/sales/volumes', [StatsSalesController::class, 'index'])->name('admin_stats_sales_volumes');
        Route::post('/admin/stats/sales/volumes/download', [StatsSalesController::class, 'download'])->name('admin_stats_sales_volumes_download');
        Route::get('/admin/stats/sales/volumes/datatable', [StatsSalesController::class, 'datatable'])->name('admin_stats_sales_volumes_datatable');

        //leads
        Route::get('/admin/leads', [LeadController::class, 'index'])->name('admin_leads');
        Route::get('/admin/lead/edit/{id}', [LeadController::class, 'edit'])->name('admin_lead_edit');
        Route::post('/admin/lead/edit/{id}', [LeadController::class, 'editPost'])->name('admin_lead_edit');

        //customers
        Route::get('/admin/customers', [CustomerController::class, 'index'])->name('admin_customers');
        Route::get('/admin/customer/detail/{id}', [CustomerController::class, 'detail'])->name('admin_customer_detail');
        Route::get('/admin/customer/edit/{id}', [CustomerController::class, 'edit'])->name('admin_customer_edit');
        Route::post('/admin/customer/edit/{id}', [CustomerController::class, 'store'])->name('admin_customer_edit');
        Route::get('/admin/customer/datatable', [CustomerController::class, 'getCustomers'])->name('admin_customer_datatable');

        Route::get('/admin/lead/change_mail/{id}', [UserUpdateEmailController::class, 'adminChangeMail'])->name('admin_lead_change_mail');
        Route::post('/admin/lead/change_mail/{id}', [UserUpdateEmailController::class, 'adminUpdateMail'])->name('admin_lead_change_mail');
        Route::get('/admin/lead/new_mail/verified/{id}', [LeadController::class, 'newMailVerified'])->name('admin_lead_new_mail_verified');
        Route::get('/admin/lead/released/{action}/{id}', [LeadController::class, 'released'])->name('admin_lead_released');
        Route::post('/admin/lead/released/{action}/{id}', [LeadController::class, 'released'])->name('admin_lead_released');

        Route::get('/admin/lead/delete/file/{user_id}/{file_id}/{relation}', [LeadController::class, 'deleteFile'])->name('admin_lead_delete_file');

        Route::post('/admin/lead/store', [LeadController::class, 'store'])->name('admin_lead_store');
        Route::get('/admin/leads/datatable', [LeadController::class, 'getLeads'])->name('admin_leads_datatable');
        Route::post('/admin/lead/download', [LeadController::class, 'download'])->name('admin_lead_download');
        Route::post('/admin/lead/update', [LeadController::class, 'update'])->name('admin_lead_update');
        Route::get('/admin/lead/remove/{action}/{user_id}/{id}/{mid?}', [LeadController::class, 'remove'])->name('admin_lead_remove');


        //sales
        Route::get('/admin/sales', [SalesController::class, 'index'])->name('admin_sales');
        Route::get('/admin/sales/detail/{id}', [SalesController::class, 'detail'])->name('admin_sales_detail');
        Route::post('/admin/sales/detail/{id}', [SalesController::class, 'detailStore'])->name('admin_sales_detail');
        Route::get('/admin/sales/datatable', [SalesController::class, 'datatable'])->name('admin_sales_datatable');

        Route::get('/admin/sales/send_logistic_mail/{id}', [SalesController::class, 'sendLogisticMail'])->name('admin_sales_send_logistic_mail');

        /*
        Route::get('/admin/sales/users', [SalesController::class, 'users'])->name('admin_sales_users');
        Route::get('/admin/sales/users/detail/{id}', [SalesController::class, 'usersDetail'])->name('admin_sales_users_detail');
        Route::post('/admin/sales/users/detail/{id}', [SalesController::class, 'usersStore'])->name('admin_sales_users_detail');
        Route::get('/admin/sales/users/datatable', [SalesController::class, 'usersDatatable'])->name('admin_sales_users_datatable');

        Route::get('/admin/sales/customers', [SalesController::class, 'customers'])->name('admin_sales_customers');
        Route::get('/admin/sales/customers/detail/{id}', [SalesController::class, 'customersDetail'])->name('admin_sales_customers_detail');
        Route::post('/admin/sales/customers/detail/{id}', [SalesController::class, 'customersStore'])->name('admin_sales_customers_detail');
        Route::get('/admin/sales/customers/datatable', [SalesController::class, 'customersDatatable'])->name('admin_sales_customers_datatable');
        */
        Route::post('/admin/sales/store', [SalesController::class, 'store'])->name('admin_sales_store');
        Route::post('/admin/sales/invoice', [SalesController::class, 'invoice'])->name('admin_sales_invoice');

        //payments
        Route::get('/admin/payments/credit', [PaymentCreditController::class, 'index'])->name('admin_payments_credit');
        Route::post('/admin/payments/credit', [PaymentCreditController::class, 'store'])->name('admin_payments_credit');
        Route::get('/admin/payments/credit/datatable', [PaymentCreditController::class, 'datatable'])->name('admin_payments_credit_datatable');
        Route::post('/admin/payments/credit/create', [PaymentCreditController::class, 'create'])->name('admin_payments_credit_create');
        Route::get('/admin/payments/credit/delete/{id}/{del?}', [PaymentCreditController::class, 'delete'])->name('admin_payments_credit_delete');


        Route::get('/admin/payments/paycredit', [PaymentPayCreditController::class, 'index'])->name('admin_payments_paycredit');
        Route::post('/admin/payments/paycredit', [PaymentPayCreditController::class, 'store'])->name('admin_payments_paycredit');
        Route::get('/admin/payments/paycredit/datatable', [PaymentPayCreditController::class, 'datatable'])->name('admin_payments_paycredit_datatable');
        Route::get('/admin/payments/paycredit/delete/{id}', [PaymentPayCreditController::class, 'delete'])->name('admin_payments_paycredit_delete');

        Route::get('/admin/payments/invoice', [PaymentInvoiceController::class, 'index'])->name('admin_payments_invoice');
        Route::post('/admin/payments/invoice', [PaymentInvoiceController::class, 'index'])->name('admin_payments_invoice');
        Route::get('/admin/payments/invoice/datatable', [PaymentInvoiceController::class, 'datatable'])->name('admin_payments_invoice_datatable');

        Route::get('/admin/payments/reminder', [PaymentReminderController::class, 'index'])->name('admin_payments_reminder');
        Route::get('/admin/payments/reminder/create', [PaymentReminderController::class, 'create'])->name('admin_payments_reminder_create');
        Route::get('/admin/payments/reminder/edit/{id}', [PaymentReminderController::class, 'edit'])->name('admin_payments_reminder_edit');
        Route::post('/admin/payments/reminder/store', [PaymentReminderController::class, 'store'])->name('admin_payments_reminder_store');
        Route::get('/admin/payments/reminder/action/{action}/{id}', [PaymentReminderController::class, 'action'])->name('admin_payments_reminder_action');
        Route::get('/admin/payments/reminder/logs', [PaymentReminderController::class, 'logs'])->name('admin_payments_reminder_logs');

        Route::get('/admin/payments/reminder/delete/{id}', [PaymentReminderController::class, 'delete'])->name('admin_payments_reminder_delete');



        Route::get('/admin/promotions', [AdminPromotionController::class, 'index'])->name('admin_promotions');
        Route::get('/admin/promotion/detail/{id}', [AdminPromotionController::class, 'detail'])->name('admin_promotion_detail');
        Route::post('/admin/promotion/detail/{id}', [AdminPromotionController::class, 'store'])->name('admin_promotion_detail');
        Route::get('/admin/promotion/delete/{id}/{del?}', [AdminPromotionController::class, 'delete'])->name('admin_promotion_delete');
        Route::get('/admin/promotion/show/{by}/{id?}', [AdminPromotionController::class, 'show'])->name('admin_promotion_show');
        Route::get('/admin/promotion/datatable/{by}/{id?}', [AdminPromotionController::class, 'datatable'])->name('admin_promotion_datatable');

    });

    //login pages for superadmin
    Route::group(['middleware' => ['superadmin']], function() {
        //leads
        Route::get('/admin/users', [AdminUserController::class, 'index'])->name('admin_users');
        Route::get('/admin/user/edit/{user_id}', [AdminUserController::class, 'edit'])->name('admin_user_edit');
        Route::post('/admin/user/store', [AdminUserController::class, 'store'])->name('admin_user_store');
        Route::get('/admin/user/delete/{user_id}', [AdminUserController::class, 'deleteUser'])->name('admin_user_delete');
        Route::get('/admin/user/login_as/{userId?}', [AdminUserController::class, 'userLoginAs'])->name('admin_user_login_as');


        Route::get('/admin/shippings', [ShippingController::class, 'index'])->name('admin_shippings');
        Route::get('/admin/shipping/edit/{shipping_id}', [ShippingController::class, 'edit'])->name('admin_shipping_edit');
        Route::post('/admin/shipping/store', [ShippingController::class, 'store'])->name('admin_shipping_store');
        Route::get('/admin/shipping/delete/{shipping_id}', [ShippingController::class, 'deleteShipping'])->name('admin_shipping_delete');
        Route::get('/admin/shipping/price/delete/{price_id}', [ShippingController::class, 'deletePrice'])->name('admin_shipping_price_delete');
        Route::get('/admin/shipping/country/delete/{price_id}', [ShippingController::class, 'deleteCountry'])->name('admin_shipping_country_delete');

        Route::get('data_table', [DataTableController::class, 'datatable'])->name('data_table');
        Route::get('data/table/users', [DataTableController::class, 'getUsers'])->name('data_table_users');

        Route::get('/admin/payment_methods', [PaymentMethodController::class, 'index'])->name('admin_payment_methods');
        Route::post('/admin/payment_method/store', [PaymentMethodController::class, 'store'])->name('admin_payment_method_store');

        Route::get('/admin/lead_types', [LeadTypeController::class, 'index'])->name('admin_lead_types');
        Route::post('/admin/lead_types/store', [LeadTypeController::class, 'store'])->name('admin_lead_types_store');


        Route::get('/admin/countries', [CountryController::class, 'index'])->name('admin_countries');
        Route::get('/admin/country/edit/{id}', [CountryController::class, 'edit'])->name('admin_country_edit');
        Route::post('/admin/country/store', [CountryController::class, 'store'])->name('admin_country_store');

        Route::get('/admin/levels', [UserLevelController::class, 'index'])->name('admin_levels');
        Route::get('/admin/level/edit/{id}', [UserLevelController::class, 'edit'])->name('admin_level_edit');
        Route::post('/admin/level/store', [UserLevelController::class, 'store'])->name('admin_level_store');
        Route::get('/admin/level/delete/{do}/{id}', [UserLevelController::class, 'delete'])->name('admin_level_delete');


        Route::get('/admin/settings', [SettingController::class, 'index'])->name('admin_settings');
        Route::post('/admin/setting/store', [SettingController::class, 'store'])->name('admin_setting_store');

    });

    //login pages for sysadmin
    Route::group(['middleware' => ['sysadmin']], function() {
        Route::get('/sysadmin/tools/{action}', [AdminToolsController::class, 'index'])->name('sysadmin_tools');
        Route::post('/sysadmin/tools/{action}', [AdminToolsController::class, 'store'])->name('sysadmin_tools');

    });
});


Route::domain(config('app.promo_domain'))->group(function () {
    Route::get("/", [PromotionController::class, 'serve'])->where('path', '.+');
    Route::post('/web/promotion/modal/load', [PromotionController::class, 'load'])->name('web_promotion_modal_load');
    Route::post('/web/promotion/store/{id}', [PromotionController::class, 'store'])->name('web_promotion_store');
    Route::get("/web/promotion/goto/{load}/{id}/{payid?}/{reference?}/{identifier?}", [PromotionController::class, 'goto'])->name('web_promotion_goto');

    Route::get('/web/paypal_payment/success/{for}/{id}/{payid?}/{reference?}/{identifier?}', [PayPalController::class, 'paymentSuccess'])->name('success.paypal_payment');
    Route::get('/web/paypal_payment/cancel/{for}/{id}/{payid?}/{reference?}/{identifier?}', [PayPalController::class, 'paymentCancel'])->name('cancel.paypal_payment');
    
    Route::get("/{path?}", [PromotionController::class, 'serve'])->where('path', '.+');
});


Route::domain(config('app.shop_domain'))->group(function () {
    Route::get("/", [ShopController::class, 'serve'])->where('path', '.+');
    Route::post('/web/shop/modal/load', [ShopController::class, 'load'])->name('web_shop_modal_load');
    Route::post('/web/shop/store/{id}', [ShopController::class, 'store'])->name('web_shop_store');
    Route::get("/web/shop/goto/{load}/{id}/{payid?}/{reference?}/{identifier?}", [ShopController::class, 'goto'])->name('web_shop_goto');

    Route::get('/web/paypal_payment/success/{for}/{id}/{payid?}/{reference?}/{identifier?}', [PayPalController::class, 'paymentSuccess'])->name('success.paypal_payment');
    Route::get('/web/paypal_payment/cancel/{for}/{id}/{payid?}/{reference?}/{identifier?}', [PayPalController::class, 'paymentCancel'])->name('cancel.paypal_payment');
    
    Route::get("/{path?}", [ShopController::class, 'serve'])->where('path', '.+');
});