<?php

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

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\PasswordOtpController;

use App\Http\Controllers\WelcomeController;
use App\Http\Controllers\GraphqlReadOnlyController;

use App\Http\Controllers\DashboardController as UserDashboardController;
use App\Http\Controllers\UserEmailController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\UserJobController;
use App\Http\Controllers\UserGmailSaleController;
use App\Http\Controllers\User\GmailSubmissionController;
use App\Http\Controllers\User\PasswordController;
use App\Http\Controllers\User\SmartLeadershipController;
use App\Http\Controllers\User\TelegramSellController;
use App\Http\Controllers\User\ActivationRequestController;

use App\Http\Controllers\WalletController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\IncomeController;
use App\Http\Controllers\ReferralController;
use App\Http\Controllers\OfferController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\ShopController;
use App\Http\Controllers\FavoriteController;
use App\Http\Controllers\LocationController;
use App\Http\Controllers\PdOrderHistoryController;
use App\Http\Controllers\ResellerDashboardController;
use App\Http\Controllers\IncomeHistoryController;
use App\Http\Controllers\SalaryController;
use App\Http\Controllers\ActivationController;
use App\Http\Controllers\AddMoneyController;
use App\Http\Controllers\UserPaymentController;
use App\Http\Controllers\WithdrawController;
use App\Http\Controllers\DrivePackController;
use App\Http\Controllers\CourseController;
use App\Http\Controllers\InAccountController;
use App\Http\Controllers\FbSubmissionController;
use App\Http\Controllers\ReviewController;
use App\Http\Controllers\SeoController;
use App\Http\Controllers\VoucherTransactionController;
use App\Http\Controllers\ProjectNoticeController;
use App\Http\Controllers\WelcomeOfferController;
use App\Http\Controllers\TypingJobController;
use App\Http\Controllers\Admin\TypingJobAdminController;
use App\Http\Controllers\Admin\TypingJobSettingsAdminController;

use App\Http\Controllers\Admin\AuthController as AdminAuthController;
use App\Http\Controllers\Admin\SubAdminController;
use App\Http\Controllers\Admin\DashboardController as AdminDashboardController;
use App\Http\Controllers\Admin\WithdrawSettingController;
use App\Http\Controllers\Admin\WithdrawRequestController;
use App\Http\Controllers\Admin\GeneralSettingsController;
use App\Http\Controllers\Admin\PaymentController;
use App\Http\Controllers\Admin\GmailSellSettingController;
use App\Http\Controllers\Admin\GmailSaleController;
use App\Http\Controllers\Admin\JobController;
use App\Http\Controllers\Admin\AdminJobSubmissionController;
use App\Http\Controllers\Admin\InSettingController;
use App\Http\Controllers\Admin\PdCategoryController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\PdOrderAdminController;
use App\Http\Controllers\Admin\SmartLeadershipAdminController;
use App\Http\Controllers\Admin\ReviewController as AdminReviewController;
use App\Http\Controllers\Admin\DashboardProjectController;
use App\Http\Controllers\Admin\FinanceController;
use App\Http\Controllers\Admin\DGAdminServiceController;
use App\Http\Controllers\Admin\CourseAdminController;
use App\Http\Controllers\Admin\VideoAdminController;
use App\Http\Controllers\Admin\SessionAdminController;
use App\Http\Controllers\Admin\BalanceController;
use App\Http\Controllers\Admin\BulkEmailController;
use App\Http\Controllers\Admin\ActivationRequestAdminController;
use App\Http\Controllers\Admin\VendorShipAdminController;

use App\Http\Controllers\AdminController;
use App\Http\Controllers\AdminUserController;
use App\Http\Controllers\AdminJobController;
use App\Http\Controllers\AdminOfferController;
use App\Http\Controllers\FbAdminController;

use App\Http\Controllers\AdminAuth\AdminPasswordResetController;
use App\Http\Controllers\LeadershipController;

use App\Http\Controllers\User\RechargeController as UserRechargeController;
use App\Http\Controllers\Admin\RechargeSettingController as AdminRechargeSettingController;
use App\Http\Controllers\Admin\RechargeAdminController;
use App\Http\Controllers\Admin\WelcomeOfferAdminController;
use App\Http\Controllers\Admin\AdminActivityLockController;
use App\Http\Controllers\Admin\SecurityCredentialController;
use App\Http\Controllers\Admin\GraphqlReadOnlyPageController;

use App\Http\Controllers\Admin\LeadershipRankController;
use App\Http\Controllers\Admin\LeadershipClaimController;

use App\Http\Controllers\VendorShip\VendorApplicationController;
use App\Http\Controllers\VendorShip\VendorDashboardController;
use App\Http\Controllers\VendorShip\VendorProductController;

Route::post('/graphql/read-only', GraphqlReadOnlyController::class)->name('graphql.read-only');

Route::prefix('admin')->middleware(['auth:admin', 'admin.project.access', 'admin.activity.log'])->name('admin.')->group(function () {

    // ✅ Leadership - Ranks Control
    Route::get('/leadership/ranks', [LeadershipRankController::class, 'index'])->name('leadership.ranks.index');
    Route::get('/leadership/ranks/create', [LeadershipRankController::class, 'create'])->name('leadership.ranks.create');
    Route::post('/leadership/ranks', [LeadershipRankController::class, 'store'])->name('leadership.ranks.store');
    Route::get('/leadership/ranks/{rank}/edit', [LeadershipRankController::class, 'edit'])->name('leadership.ranks.edit');
    Route::put('/leadership/ranks/{rank}', [LeadershipRankController::class, 'update'])->name('leadership.ranks.update');
    Route::patch('/leadership/ranks/{rank}/toggle', [LeadershipRankController::class, 'toggle'])->name('leadership.ranks.toggle');
    Route::delete('/leadership/ranks/{rank}', [LeadershipRankController::class, 'destroy'])->name('leadership.ranks.destroy');

    // ✅ Leadership - Claims History
    Route::get('/leadership/claims', [LeadershipClaimController::class, 'index'])->name('leadership.claims.index');
});
Route::middleware(['auth'])->group(function () {

    Route::get('/leadership', [LeadershipController::class, 'myProgress'])->name('leadership.progress');
    Route::get('/leadership/rank/{key}', [LeadershipController::class, 'showRank'])->name('leadership.rank.show');
    Route::post('/leadership/claim/{rankId}', [LeadershipController::class, 'claim'])->name('leadership.claim');
    Route::get('/leadership/history', [LeadershipController::class, 'history'])->name('leadership.history');

    Route::get('/smart-leadership', [SmartLeadershipController::class, 'index'])->name('user.smart.leadership.index');
    Route::post('/smart-leadership/claim', [SmartLeadershipController::class, 'claim'])->name('user.smart.leadership.claim');
    Route::get('/smart-leadership/history', [SmartLeadershipController::class, 'history'])->name('user.smart.leadership.history');

});

Route::get('/', [WelcomeController::class, 'index'])->name('welcome');
Route::get('/robots.txt', [SeoController::class, 'robots'])->name('seo.robots');
Route::get('/sitemap.xml', [SeoController::class, 'sitemap'])->name('seo.sitemap');
Route::get('/site.webmanifest', [SeoController::class, 'manifest'])->name('seo.manifest');
Route::view('/policy/reselling', 'policy.reselling')->name('policy.reselling');
Route::get('/shop', [ShopController::class, 'index'])->name('shop.index');
Route::get('/search', [ShopController::class, 'search'])->name('shop.search');
Route::get('/product/{slug}', [ShopController::class, 'product'])->name('shop.product');
Route::get('/category/{slug}', [ShopController::class, 'categoryOnly'])->name('shop.category');
Route::get('/shop/categories', [ShopController::class, 'allCategories'])->name('shop.categories.all');
Route::get('/shop/vendors', [ShopController::class, 'vendorSearch'])->name('shop.vendors.index');
Route::get('/shop/vendors/{vendorProfile}', [ShopController::class, 'vendorProfile'])->name('shop.vendors.show');

Route::get('/register', [RegisteredUserController::class, 'create'])->name('register');
Route::post('/register', [RegisteredUserController::class, 'store']);

Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login.form');
Route::post('/login', [LoginController::class, 'store'])->name('login');

Route::get('/forgot', [PasswordOtpController::class, 'showRequestForm'])->name('password.otp.request');
Route::post('/forgot', [PasswordOtpController::class, 'sendOtp'])->name('password.otp.send');
Route::get('/reset/verify', [PasswordOtpController::class, 'showVerifyForm'])->name('password.otp.verify.form');
Route::post('/reset/verify', [PasswordOtpController::class, 'verifyAndReset'])->name('password.otp.verify');

Route::post('/logout', function () {
    Auth::logout();
    request()->session()->invalidate();
    request()->session()->regenerateToken();
    return redirect('/login')->with('success', 'লগআউট সফল হয়েছে।');
})->name('logout');

Route::get('admin/password/forgot', [AdminPasswordResetController::class, 'showRequestForm'])->name('admin.password.request');
Route::post('admin/password/forgot', [AdminPasswordResetController::class, 'sendOtp'])->name('admin.password.email');
Route::get('admin/password/verify', [AdminPasswordResetController::class, 'showVerifyForm'])->name('admin.password.verify.form');
Route::post('admin/password/verify', [AdminPasswordResetController::class, 'verifyOtp'])->name('admin.password.verify');
Route::get('admin/password/reset', [AdminPasswordResetController::class, 'showResetForm'])->name('admin.password.reset.form');
Route::post('admin/password/reset', [AdminPasswordResetController::class, 'resetPassword'])->name('admin.password.update');

Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/login', [AdminAuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AdminAuthController::class, 'login'])->name('login.submit');
    Route::post('/logout', [AdminAuthController::class, 'logout'])->name('logout');
});

Route::middleware(['auth'])->group(function () {
    Route::view('/agent', 'user.agent');
    Route::view('/social', 'user.social');
    Route::view('/ticket', 'user.ticket');

    Route::view('/visionary-captain', 'leadership.visionary-captain');
    Route::view('/success-commander', 'leadership.success-commander');
    Route::view('/growth-director', 'leadership.growth-director');
    Route::view('/growth-mentor', 'leadership.growth-mentor');
    Route::view('/master-leader', 'leadership.master-leader');

    // auth middleware এর ভিতরে
    Route::get('/referrals/user/{id}/profile', [\App\Http\Controllers\ReferralController::class, 'userProfile'])
        ->name('referrals.user.profile');

    Route::view('/aboutus', 'user.aboutus');
    Route::view('/contact', 'user.contact');
    Route::view('/privacy_policy', 'user.privacy_policy');

    Route::get('/dashboard', [UserDashboardController::class, 'index'])->name('dashboard');
    Route::post('/user/update-email', [UserEmailController::class, 'store'])->name('user.update-email');

    Route::get('/course', [CourseController::class, 'dashboard'])->name('course.dashboard');
    Route::get('/course/{course}', [CourseController::class, 'show'])->name('course.show')->whereNumber('course');
    Route::get('/course/session/{session}', [CourseController::class, 'session'])->name('course.session');
    Route::get('/course/video/{video}', [CourseController::class, 'watch'])->name('course.watch');
    Route::post('/course/video/{video}/progress', [CourseController::class, 'progress'])->name('course.progress');

    Route::get('/targets', [\App\Http\Controllers\TargetBonusController::class, 'index'])->name('targets.index');
    Route::post('/targets/{target}/claim', [\App\Http\Controllers\TargetBonusController::class, 'claim'])->name('targets.claim');

    Route::get('/instagram/submit', [InAccountController::class, 'create'])
        ->name('user.instagram.create');

    // 👉 Instagram Account Submit Page
    Route::get('/in/create', [InAccountController::class, 'create'])
        ->name('in.create');

    // 👉 Instagram Account Submit (POST)
    Route::post('/in/submit', [InAccountController::class, 'store'])
        ->name('in.submit');

    // 👉 User Submission History (with status filter)
    Route::get('/in/history', [InAccountController::class, 'userHistory'])
        ->name('in.history');

    Route::get('/telegram-sell-info', [TelegramSellController::class, 'index'])->name('telegram.sell.info');
    Route::get('/welcome-offer', [WelcomeOfferController::class, 'index'])->name('welcome-offer.index');
    Route::get('/welcome-offer/history/{level}', [WelcomeOfferController::class, 'history'])
        ->whereNumber('level')
        ->name('welcome-offer.history');
    Route::post('/welcome-offer/claim', [WelcomeOfferController::class, 'claim'])->name('welcome-offer.claim');
    Route::get('/typing-job', [TypingJobController::class, 'index'])->name('typing-job.index');
    Route::get('/typing-job/history', [TypingJobController::class, 'history'])->name('typing-job.history');
    Route::post('/typing-job/submit', [TypingJobController::class, 'submit'])->name('typing-job.submit');
    Route::get('/quiz-job', [ProjectNoticeController::class, 'show'])
        ->defaults('slug', 'quiz-job')
        ->name('project.notice.quiz_job');
    Route::get('/telegram-sell', [ProjectNoticeController::class, 'show'])
        ->defaults('slug', 'telegram-sell')
        ->name('project.notice.telegram_sell');

    Route::get('/salary', [SalaryController::class, 'show'])->name('salary.index');
    Route::post('/claim-salary', [SalaryController::class, 'claim'])->name('claim.salary');

    Route::get('/income-history', [IncomeHistoryController::class, 'index'])->name('income.history');

    Route::get('/activation', [ActivationRequestController::class, 'form'])->name('activation.form');
    Route::post('/activation', [ActivationRequestController::class, 'submit'])->name('activation.submit');
    Route::post('/activation/voucher', [ActivationRequestController::class, 'verifyWithVoucher'])->name('activation.voucher');
    Route::get('/activation/success', [ActivationRequestController::class, 'success'])->name('activation.success');




    Route::get('/offers', [OfferController::class, 'index'])->name('offers.filter');
    Route::post('/buy-offer/{id}', [OfferController::class, 'buy'])->name('buy.offer');
    Route::get('/orders/history', [OfferController::class, 'userHistory'])->name('orders.history');

    Route::prefix('voucher')->group(function () {
        Route::get('/', fn() => view('user.voucher'))->name('user.voucher');
        Route::get('/transactions', [VoucherTransactionController::class, 'index'])->name('user.voucher.transactions');
    });

    Route::get('/level/{level}', [ReferralController::class, 'showLevel']);
    Route::get('/my-team', [ReferralController::class, 'showLevels']);
    Route::get('/referrals/all', [ReferralController::class, 'showAllLevels'])->name('referrals.all');

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

    Route::get('/income-summary', fn() => view('user.income.summary'))->name('income.summary');

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::put('/profile', [ProfileController::class, 'update'])->name('profile.update');

    Route::get('/user/change-password', [PasswordController::class, 'index'])->name('user.change.password');
    Route::post('/user/change-password', [PasswordController::class, 'update'])->name('user.change.password.update');

    Route::get('/income/today', [IncomeController::class, 'today'])->name('income.today');
    Route::get('/income/yesterday', [IncomeController::class, 'yesterday'])->name('income.yesterday');
    Route::get('/income/last-7-days', [IncomeController::class, 'last7'])->name('income.last7');
    Route::get('/income/last-30-days', [IncomeController::class, 'last30'])->name('income.last30');
    Route::get('/income/total', [IncomeController::class, 'total'])->name('income.total');

    Route::get('/withdraw', [WithdrawController::class, 'create'])->name('withdraw.form');
    Route::post('/withdraw', [WithdrawController::class, 'store'])->name('withdraw.submit');
    Route::get('/user/withdraw/history', [WithdrawController::class, 'history'])->name('withdraw.history');

    Route::get('/my-payments', [UserPaymentController::class, 'index'])->name('user.payments');
    Route::get('/my-payments/export', [UserPaymentController::class, 'export'])->name('user.payments.export');


    Route::get('/drive-packs', [DrivePackController::class, 'index'])->name('drive.index');
    Route::post('/drive-packs/refresh', [DrivePackController::class, 'refresh'])->name('drive.refresh');
    Route::post('/drive-packs/purchase', [DrivePackController::class, 'purchase'])->name('drive.purchase');

    Route::get('/pd-orders', [PdOrderHistoryController::class, 'index'])->name('user.pdorders');
    Route::get('/pd-orders/{pdorder}', [PdOrderHistoryController::class, 'show'])->name('user.pdorders.show');

    Route::get('/favorites', [FavoriteController::class, 'index'])->name('user.favorites.index');
    Route::post('/favorites/add/{product}', [FavoriteController::class, 'store'])->name('user.favorites.add');
    Route::post('/favorites/remove/{product}', [FavoriteController::class, 'destroy'])->name('user.favorites.remove');

    Route::get('/vendor-ship', function () {
        return redirect()->route('vendor-ship.profile');
    })->name('vendor-ship.home');

    Route::prefix('vendor-ship')->name('vendor-ship.')->group(function () {
        Route::get('/apply', [VendorApplicationController::class, 'index'])->name('apply');
        Route::post('/apply', [VendorApplicationController::class, 'submit'])->name('submit');

        Route::get('/profile', [VendorDashboardController::class, 'profile'])->name('profile');
        Route::get('/orders', [VendorDashboardController::class, 'orders'])->name('orders');
        Route::get('/orders/{vendorOrder}', [VendorDashboardController::class, 'showOrder'])->name('orders.show');
        Route::patch('/orders/{vendorOrder}/status', [VendorDashboardController::class, 'updateOrderStatus'])->name('orders.status');
        Route::patch('/orders/{vendorOrder}/tracking', [VendorDashboardController::class, 'updateTracking'])->name('orders.tracking');

        Route::prefix('products')->name('products.')->group(function () {
            Route::get('/', [VendorProductController::class, 'index'])->name('index');
            Route::get('/create', [VendorProductController::class, 'create'])->name('create');
            Route::post('/', [VendorProductController::class, 'store'])->name('store');
            Route::get('/pending', [VendorProductController::class, 'pending'])->name('pending');
            Route::get('/approved', [VendorProductController::class, 'approved'])->name('approved');
            Route::get('/rejected', [VendorProductController::class, 'rejected'])->name('rejected');
            Route::get('/{vendorProduct}/edit', [VendorProductController::class, 'edit'])->name('edit');
            Route::put('/{vendorProduct}', [VendorProductController::class, 'update'])->name('update');
            Route::delete('/{vendorProduct}', [VendorProductController::class, 'destroy'])->name('destroy');
        });
    });

    Route::get('/reseller/dashboard', ResellerDashboardController::class)
        ->name('reseller.dashboard');

    Route::get('/checkout/{slug}', [OrderController::class, 'create'])->name('order.create');
    Route::post('/checkout/{product}', [OrderController::class, 'store'])->name('order.store');
    Route::get('/checkout/{product}/customer', [OrderController::class, 'customer'])->name('order.customer');
    Route::post('/checkout/{product}/confirm', [OrderController::class, 'confirm'])->name('order.confirm');

    Route::prefix('location')->name('location.')->group(function () {
        Route::get('/districts', [LocationController::class, 'allDistricts'])->name('districts.all');
        Route::get('/divisions', [LocationController::class, 'divisions'])->name('divisions');
        Route::get('/districts/{division}', [LocationController::class, 'districts'])->name('districts');
        Route::get('/upazilas/{district}', [LocationController::class, 'upazilas'])->name('upazilas');
    });

    Route::get('/gmail-sell', [GmailSubmissionController::class, 'gmailSellForm'])->name('user.gmail.sell');
    Route::post('/gmail-sell', [GmailSubmissionController::class, 'submit'])->name('user.gmail.submit');
    Route::get('/user/gmail-sales-history/{status?}', [UserGmailSaleController::class, 'history'])->name('user.gmail-sales.history');

    Route::get('/user/jobs/create', [UserJobController::class, 'create'])->name('user.jobs.create');
    Route::post('/user/jobs/store', [UserJobController::class, 'store'])->name('user.jobs.store');
    Route::get('/user/jobs/history', [UserJobController::class, 'myPostedJobs'])->name('user.jobs.history');

    Route::get('/micro-jobs', [UserJobController::class, 'index'])->name('microjobs.index');
    Route::get('/micro-jobs/{id}', [UserJobController::class, 'show'])->name('microjobs.show');
    Route::post('/micro-jobs/{id}/submit', [UserJobController::class, 'submit'])->name('microjobs.submit');

    Route::get('/user/jobs/{job}/submissions', [UserJobController::class, 'submissions'])->name('user.jobs.submissions');
    Route::put('/user/job-submission/{submission}', [UserJobController::class, 'updateSubmissionStatus'])->name('user.job-submission.update');
    Route::get('/user/jobs/{job}/submissions/pending', [UserJobController::class, 'showPendingSubmissions'])->name('user.jobs.submissions.pending');
    Route::get('/user/jobs/{job}/submissions/reviewed', [UserJobController::class, 'showReviewedSubmissions'])->name('user.jobs.submissions.reviewed');

    Route::get('/my-job-history', [UserJobController::class, 'userFilteredHistory'])->name('user.job_history');

    Route::prefix('fb/marketing')->group(function () {
        Route::get('/', [FbSubmissionController::class, 'showForm']);
        Route::post('/', [FbSubmissionController::class, 'submitForm']);
        Route::get('/history/{status?}', [FbSubmissionController::class, 'submissionHistory']);
    });

    Route::middleware(['verified'])->group(function () {
        Route::view('/helpline', 'user.helpline')->name('user.helpline');
        Route::view('/payment', 'user.payment')->name('user.payment');
        Route::view('/about', 'user.about')->name('user.about');
        Route::view('/update', 'update')->name('update');
        Route::view('/developer', 'developer')->name('developer');
        Route::view('/learn', 'user.learn')->name('user.learn');
        Route::view('/privacy', 'user.privacy')->name('user.privacy');
    });

    Route::get('/reviews', [ReviewController::class, 'index'])->name('reviews.index');
    Route::post('/reviews', [ReviewController::class, 'store'])->name('reviews.store');

    Route::post('/activate/pay', [ActivationController::class, 'createPayment'])->name('activate.pay');

    Route::get('/wallet/add', [AddMoneyController::class, 'form'])->name('addmoney.form');
    Route::post('/wallet/add/create', [AddMoneyController::class, 'createPayment'])->name('addmoney.create');

    Route::delete('/user/dismiss-message', [UserController::class, 'dismissMessage'])->name('user.dismissMessage');

    Route::get('/dg-services', [\App\Http\Controllers\User\DGUserServiceController::class, 'index'])->name('user.dg_services.index');
    Route::get('/dg-services/{id}', [\App\Http\Controllers\User\DGUserServiceController::class, 'show'])->name('user.dg_services.show');
    Route::post('/dg-services/{id}/order', [\App\Http\Controllers\User\DGUserServiceController::class, 'order'])->name('user.dg_services.order');

    Route::get('/salary/step-1-members', [SalaryController::class, 'showStep1Members'])->name('salary.step1.members');
    Route::get('/salary/step-2-members', [SalaryController::class, 'showStep2Members'])->name('salary.step2.members');
});

Route::get('/payment/success', [ActivationController::class, 'paymentSuccess'])->name('payment.success');
Route::get('/payment/cancel', [ActivationController::class, 'paymentCancel'])->name('payment.cancel');
Route::get('/wallet/add/success', [AddMoneyController::class, 'paymentSuccess'])->name('addmoney.success');
Route::get('/wallet/add/cancel', [AddMoneyController::class, 'paymentCancel'])->name('addmoney.cancel');
Route::post('/webhook/payfastbd/activation', [ActivationController::class, 'handleWebhook'])->name('payfastbd.activation.webhook');
Route::post('/webhook/payfastbd/wallet', [AddMoneyController::class, 'handleWebhook'])->name('payfastbd.wallet.webhook');
Route::post('/webhook/bondhonpay', [AddMoneyController::class, 'handleWebhook'])->name('bondhonpay.webhook');

Route::prefix('admin')->middleware(['auth:admin', 'admin.project.access', 'admin.activity.log'])->name('admin.')->group(function () {

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

    Route::prefix('vendor-ship')->name('vendor-ship.')->group(function () {
        Route::get('/vendors', [VendorShipAdminController::class, 'vendors'])->name('vendors');
        Route::get('/vendors/{vendorProfile}', [VendorShipAdminController::class, 'vendorsShow'])->name('vendors.show');
        Route::post('/vendors/{vendorProfile}/approve', [VendorShipAdminController::class, 'vendorsApprove'])->name('vendors.approve');
        Route::post('/vendors/{vendorProfile}/reject', [VendorShipAdminController::class, 'vendorsReject'])->name('vendors.reject');

        Route::get('/products', [VendorShipAdminController::class, 'products'])->name('products');
        Route::get('/products/{vendorProduct}/edit', [VendorShipAdminController::class, 'productsEdit'])->name('products.edit');
        Route::put('/products/{vendorProduct}', [VendorShipAdminController::class, 'productsUpdate'])->name('products.update');
        Route::post('/products/{vendorProduct}/approve', [VendorShipAdminController::class, 'productsApprove'])->name('products.approve');
        Route::post('/products/{vendorProduct}/reject', [VendorShipAdminController::class, 'productsReject'])->name('products.reject');
        Route::delete('/products/{vendorProduct}', [VendorShipAdminController::class, 'productsDestroy'])->name('products.destroy');

        Route::get('/orders', [VendorShipAdminController::class, 'orders'])->name('orders');
        Route::get('/orders/{vendorOrder}/edit', [VendorShipAdminController::class, 'ordersEdit'])->name('orders.edit');
        Route::put('/orders/{vendorOrder}', [VendorShipAdminController::class, 'ordersUpdate'])->name('orders.update');

        Route::prefix('orders/location')->name('orders.location.')->group(function () {
            Route::get('/divisions', [VendorShipAdminController::class, 'locationDivisions'])->name('divisions');
            Route::get('/districts/{division}', [VendorShipAdminController::class, 'locationDistricts'])->name('districts');
            Route::get('/upazilas/{district}', [VendorShipAdminController::class, 'locationUpazilas'])->name('upazilas');
        });
    });

    Route::prefix('sub-admins')->name('sub-admins.')->middleware('super.admin')->group(function () {
        Route::get('/', [SubAdminController::class, 'index'])->name('index');
        Route::get('/create', [SubAdminController::class, 'create'])->name('create');
        Route::post('/', [SubAdminController::class, 'store'])->name('store');
        Route::get('/{subAdmin}/edit', [SubAdminController::class, 'edit'])->name('edit');
        Route::put('/{subAdmin}', [SubAdminController::class, 'update'])->name('update');
        Route::delete('/{subAdmin}', [SubAdminController::class, 'destroy'])->name('destroy');
    });

    Route::prefix('activity-lock')->name('activity-lock.')->middleware('super.admin')->group(function () {
        Route::get('/', [AdminActivityLockController::class, 'index'])->name('index');
    });

    Route::prefix('security-credentials')->name('security-credentials.')->middleware('super.admin')->group(function () {
        Route::get('/', [SecurityCredentialController::class, 'edit'])->name('edit');
        Route::post('/', [SecurityCredentialController::class, 'update'])->name('update');
    });

    Route::get('/graphql-read-only', [GraphqlReadOnlyPageController::class, 'index'])
        ->middleware('super.admin')
        ->name('graphql-read-only.index');

    Route::get('/fixed-commissions', [AdminController::class, 'editCommissions'])->name('fixedCommissions.edit');
    Route::post('/fixed-commissions', [AdminController::class, 'updateCommissions'])->name('fixedCommissions.update');

    Route::get('/email/broadcast', [BulkEmailController::class, 'create'])->name('email.create');
    Route::get('/email/broadcast/recipient-count', [BulkEmailController::class, 'recipientCount'])->name('email.recipient-count');
    Route::post('/email/broadcast', [BulkEmailController::class, 'store'])->name('email.store');

    Route::get('/balance/update', [BalanceController::class, 'showUpdateForm'])->name('balance.form');
    Route::post('/balance/update', [BalanceController::class, 'update'])->name('balance.update');
    Route::get('/balance/fetch-user', [BalanceController::class, 'fetchUser'])->name('balance.fetch');

    Route::get('/courses', [CourseAdminController::class, 'index'])->name('courses.index');
    Route::get('/courses/create', [CourseAdminController::class, 'create'])->name('courses.create');
    Route::post('/courses', [CourseAdminController::class, 'store'])->name('courses.store');
    Route::get('/courses/{course}/edit', [CourseAdminController::class, 'edit'])->name('courses.edit');
    Route::put('/courses/{course}', [CourseAdminController::class, 'update'])->name('courses.update');
    Route::post('/courses/banner', [CourseAdminController::class, 'updateGlobalBanner'])->name('courses.banner.update');
    Route::delete('/courses/{course}', [CourseAdminController::class, 'destroy'])->name('courses.destroy');

    Route::get('/courses/{course}/sessions', [SessionAdminController::class, 'index'])->name('sessions.index');
    Route::post('/courses/{course}/sessions', [SessionAdminController::class, 'store'])->name('sessions.store');
    Route::put('/sessions/{session}', [SessionAdminController::class, 'update'])->name('sessions.update');
    Route::delete('/sessions/{session}', [SessionAdminController::class, 'destroy'])->name('sessions.destroy');

    Route::get('/sessions/{session}/videos', [VideoAdminController::class, 'index'])->name('videos.index');
    Route::post('/sessions/{session}/videos', [VideoAdminController::class, 'store'])->name('videos.store');
    Route::put('/videos/{video}', [VideoAdminController::class, 'update'])->name('videos.update');
    Route::delete('/videos/{video}', [VideoAdminController::class, 'destroy'])->name('videos.destroy');

    Route::get('/users/{user}/uplines', [\App\Http\Controllers\AdminUserController::class, 'uplines'])
        ->name('users.uplines');

    Route::get('/activation-requests', [ActivationRequestAdminController::class, 'index'])->name('activation_requests.index');
    Route::get('/activation-requests/history', [ActivationRequestAdminController::class, 'history'])->name('activation_requests.history');
    Route::post('/activation-requests/{activationRequest}/approve', [ActivationRequestAdminController::class, 'approve'])->name('activation_requests.approve');
    Route::post('/activation-requests/{activationRequest}/reject', [ActivationRequestAdminController::class, 'reject'])->name('activation_requests.reject');
    Route::post('/activation-requests/manual-status', [ActivationRequestAdminController::class, 'manualStatusUpdate'])->name('activation_requests.manual_status');

    Route::prefix('targets')->name('targets.')->group(function () {
        Route::get('/', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'index'])->name('index');
        Route::get('/create', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'create'])->name('create');
        Route::post('/', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'store'])->name('store');
        Route::get('/{target}/edit', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'edit'])->name('edit');
        Route::put('/{target}', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'update'])->name('update');
        Route::patch('/{target}/toggle', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'toggle'])->name('toggle');
        Route::delete('/{target}', [\App\Http\Controllers\Admin\TargetCampaignAdminController::class, 'destroy'])->name('destroy');
    });

    Route::get('/in-settings', [InSettingController::class, 'edit'])->name('in.settings');
    Route::post('/in-settings', [InSettingController::class, 'update'])->name('in.settings.update');

    Route::get('/in/accounts', [InAccountController::class, 'adminView'])->name('in.accounts');
    Route::post('/in/accounts/update-status', [InAccountController::class, 'updateStatus'])->name('in.accounts.update');
    Route::get('/in-accounts/export', [InAccountController::class, 'export'])->name('in.accounts.export');

    Route::get('/smart-leadership', [SmartLeadershipAdminController::class, 'index'])->name('smart.index');
    Route::get('/smart-leadership/{user}', [SmartLeadershipAdminController::class, 'show'])->name('smart.show');

    Route::get('/pd-orders/{status?}', [PdOrderAdminController::class, 'index'])
        ->whereIn('status', ['pending', 'processing', 'rejected', 'approved', 'completed', 'cancelled', 'returned'])
        ->name('pdorders.index');
    Route::get('/pd-orders/show/{order}', [PdOrderAdminController::class, 'show'])->name('pdorders.show');
    Route::patch('/pd-orders/{order}/status', [PdOrderAdminController::class, 'updateStatus'])->name('pdorders.updateStatus');
    Route::patch('/pd-orders/{order}/tracking', [PdOrderAdminController::class, 'updateTracking'])->name('pdorders.updateTracking');
    Route::patch('/pd-orders/{order}/details', [PdOrderAdminController::class, 'updateDetails'])->name('pdorders.updateDetails');

    Route::prefix('products')->name('products.')->group(function () {
        Route::get('/', [ProductController::class, 'index'])->name('index');
        Route::get('/create', [ProductController::class, 'create'])->name('create');
        Route::post('/store', [ProductController::class, 'store'])->name('store');
        Route::get('/{id}/edit', [ProductController::class, 'edit'])->name('edit');
        Route::post('/{id}/update', [ProductController::class, 'update'])->name('update');
        Route::post('/{id}/delete', [ProductController::class, 'destroy'])->name('destroy');
        Route::post('/images/{imageId}/delete', [ProductController::class, 'destroyImage'])->name('images.destroy');
    });

    Route::prefix('pd-categories')->name('pd-categories.')->group(function () {
        Route::get('/', [PdCategoryController::class, 'index'])->name('index');
        Route::get('/create', [PdCategoryController::class, 'create'])->name('create');
        Route::post('/store', [PdCategoryController::class, 'store'])->name('store');
        Route::get('/{id}/edit', [PdCategoryController::class, 'edit'])->name('edit');
        Route::post('/{id}/update', [PdCategoryController::class, 'update'])->name('update');
        Route::post('/{id}/delete', [PdCategoryController::class, 'destroy'])->name('destroy');
    });

    Route::get('/offers', [AdminOfferController::class, 'index'])->name('offers.index');
    Route::get('/offers/settings', [AdminOfferController::class, 'settings'])->name('offers.settings');
    Route::post('/offers/settings', [AdminOfferController::class, 'updateSettings'])->name('offers.settings.update');
    Route::get('/offers/create', [AdminOfferController::class, 'create'])->name('offers.create');
    Route::post('/offers', [AdminOfferController::class, 'store'])->name('offers.store');
    Route::get('/offers/{id}/edit', [AdminOfferController::class, 'edit'])->name('offers.edit');
    Route::post('/offers/{id}', [AdminOfferController::class, 'update'])->name('offers.update');
    Route::post('/offers/{id}/delete', [AdminOfferController::class, 'destroy'])->name('offers.destroy');

    Route::get('/orders/pending', [\App\Http\Controllers\AdminDriveOrderController::class, 'pending'])->name('orders.pending');
    Route::get('/orders/completed', [\App\Http\Controllers\AdminDriveOrderController::class, 'completed'])->name('orders.completed');
    Route::get('/orders/cancelled', [\App\Http\Controllers\AdminDriveOrderController::class, 'cancelled'])->name('orders.cancelled');
    Route::post('/orders/{id}/complete', [\App\Http\Controllers\AdminDriveOrderController::class, 'complete'])->name('orders.complete');
    Route::post('/orders/{id}/cancel', [\App\Http\Controllers\AdminDriveOrderController::class, 'cancel'])->name('orders.cancel');

    Route::get('/jobs/pending', [AdminJobController::class, 'pending'])->name('jobs.pending');
    Route::get('/jobs/approved', [JobController::class, 'approved'])->name('jobs.approved');
    Route::get('/jobs/rejected', [JobController::class, 'rejected'])->name('jobs.rejected');
    Route::post('/jobs/{id}/approve', [AdminJobController::class, 'approve'])->name('jobs.approve');
    Route::post('/jobs/{id}/reject', [AdminJobController::class, 'reject'])->name('jobs.reject');

    Route::resource('jobs', JobController::class);

    Route::post('jobs/{job}/pause', [JobController::class, 'pause'])->name('jobs.pause');
    Route::post('jobs/{job}/resume', [JobController::class, 'resume'])->name('jobs.resume');

    Route::get('/job-submissions/pending', [AdminJobSubmissionController::class, 'pending'])->name('submissions.pending');
    Route::get('/job-submissions/approved', [AdminJobSubmissionController::class, 'approved'])->name('submissions.approved');
    Route::get('/job-submissions/rejected', [AdminJobSubmissionController::class, 'rejected'])->name('submissions.rejected');

    Route::get('/submissions', [AdminJobSubmissionController::class, 'index'])->name('submission.index');
    Route::get('/submissions/pending', [AdminJobSubmissionController::class, 'pending'])->name('submission.pending');
    Route::get('/submissions/approved', [AdminJobSubmissionController::class, 'approved'])->name('submission.approved');
    Route::get('/submissions/rejected', [AdminJobSubmissionController::class, 'rejected'])->name('submission.rejected');
    Route::put('/submission/update/{id}', [AdminJobSubmissionController::class, 'update'])->name('submission.update');

    Route::get('/withdraw-settings', [WithdrawSettingController::class, 'index'])->name('withdraw.settings');
    Route::post('/withdraw-settings/method', [WithdrawSettingController::class, 'storeMethod'])->name('withdraw.method.store');
    Route::post('/withdraw-settings/type', [WithdrawSettingController::class, 'storeType'])->name('withdraw.type.store');
    Route::post('/withdraw-settings/config', [WithdrawSettingController::class, 'storeConfig'])->name('withdraw.config.store');
    Route::post('/withdraw-settings/notice', [WithdrawSettingController::class, 'storeNotice'])->name('withdraw.notice.store');

    Route::get('/withdraw-requests/pending', [WithdrawRequestController::class, 'indexPending'])->name('withdraw.pending');
    Route::get('/withdraw-requests/approved', [WithdrawRequestController::class, 'indexApproved'])->name('withdraw.approved');
    Route::get('/withdraw-requests/rejected', [WithdrawRequestController::class, 'indexRejected'])->name('withdraw.rejected');
    Route::get('/withdraw-requests/history', [WithdrawRequestController::class, 'indexHistory'])->name('withdraw.history');
    Route::post('/withdraw-requests/{id}/approve', [WithdrawRequestController::class, 'approve'])->name('withdraw.approve');
    Route::post('/withdraw-requests/{id}/reject', [WithdrawRequestController::class, 'reject'])->name('withdraw.reject');

    Route::get('/profile', [AdminController::class, 'editProfile'])->name('profile');
    Route::post('/profile/update', [AdminController::class, 'updateProfile'])->name('profile.update');

    Route::get('/change-password', [AdminController::class, 'showChangePasswordForm'])->name('password.form');
    Route::post('/change-password', [AdminController::class, 'updatePassword'])->name('password.update');

    Route::get('/general-settings', [GeneralSettingsController::class, 'edit'])->name('general-settings.edit');
    Route::post('/general-settings', [GeneralSettingsController::class, 'update'])->name('general-settings.update');

    Route::get('/payments', [PaymentController::class, 'index'])->name('payments.index');
    Route::get('/payments/export', [PaymentController::class, 'export'])->name('payments.export');

    Route::get('/finance', [FinanceController::class, 'index'])->name('finance.index');
    Route::post('/finance/store', [FinanceController::class, 'store'])->name('finance.store');
    Route::get('/finance/export', [FinanceController::class, 'exportCsv'])->name('finance.export');

    Route::get('/gmail-setting', [GmailSellSettingController::class, 'index'])->name('gmail.setting');
    Route::post('/gmail-setting', [GmailSellSettingController::class, 'update'])->name('gmail.setting.update');
    Route::post('/gmail-setting/reset-stats', [GmailSellSettingController::class, 'resetStats'])->name('gmail.setting.reset_stats');
    Route::get('/gmail-setting-toggle', [GmailSellSettingController::class, 'toggle'])->name('gmail.setting.toggle');

    Route::get('/gmail-sales', [GmailSaleController::class, 'index'])->name('gmail.sales.index');
    Route::put('/gmail-sales/{id}/status', [GmailSaleController::class, 'updateStatus'])->name('gmail.sales.status');
    Route::get('/gmail-sales/export', [GmailSaleController::class, 'export'])->name('gmail.export');
    Route::put('/gmail-sales/bulk-action', [GmailSaleController::class, 'bulkAction'])->name('gmail.bulkAction');
    Route::get('/gmail-sales/pending', [GmailSaleController::class, 'pending'])->name('gmail.sales.pending');
    Route::get('/gmail-sales/checked', [GmailSaleController::class, 'checked'])->name('gmail.sales.checked');
    Route::get('/gmail-sales/rejected', [GmailSaleController::class, 'rejected'])->name('gmail.sales.rejected');
    Route::get('/gmail-sales/completed', [GmailSaleController::class, 'completed'])->name('gmail.sales.completed');

    Route::get('/reviews', [AdminReviewController::class, 'index'])->name('reviews.index');
    Route::delete('/reviews/{review}', [AdminReviewController::class, 'destroy'])->name('reviews.destroy');

    Route::get('/dg-services', [DGAdminServiceController::class, 'index'])->name('dg_services.index');
    Route::get('/dg-services/create', [DGAdminServiceController::class, 'create'])->name('dg_services.create');
    Route::post('/dg-services', [DGAdminServiceController::class, 'store'])->name('dg_services.store');
    Route::get('/dg-services/{id}/edit', [DGAdminServiceController::class, 'edit'])->name('dg_services.edit');
    Route::put('/dg-services/{id}', [DGAdminServiceController::class, 'update'])->name('dg_services.update');
    Route::delete('/dg-services/{id}', [DGAdminServiceController::class, 'destroy'])->name('dg_services.destroy');
    Route::post('/dg-services/{id}/toggle', [DGAdminServiceController::class, 'toggle'])->name('dg_services.toggle');

    Route::get('/dashboard-projects', [DashboardProjectController::class, 'index'])->name('dashboard-projects.index');
    Route::get('/dashboard-projects/create', [DashboardProjectController::class, 'create'])->name('dashboard-projects.create');
    Route::post('/dashboard-projects', [DashboardProjectController::class, 'store'])->name('dashboard-projects.store');
    Route::get('/dashboard-projects/{dashboard_project}/edit', [DashboardProjectController::class, 'edit'])->name('dashboard-projects.edit');
    Route::put('/dashboard-projects/{dashboard_project}', [DashboardProjectController::class, 'update'])->name('dashboard-projects.update');
    Route::delete('/dashboard-projects/{dashboard_project}', [DashboardProjectController::class, 'destroy'])->name('dashboard-projects.destroy');
    Route::patch('/dashboard-projects/{dashboard_project}/toggle', [DashboardProjectController::class, 'toggle'])->name('dashboard-projects.toggle');
    Route::post('/dashboard-projects/inactive-global', [DashboardProjectController::class, 'updateInactiveGlobal'])->name('dashboard-projects.inactive-global');

    Route::get('/recharge-settings', [AdminRechargeSettingController::class, 'edit'])->name('recharge.settings.edit');
    Route::post('/recharge-settings', [AdminRechargeSettingController::class, 'update'])->name('recharge.settings.update');
    Route::post('/recharge-settings/balance', [AdminRechargeSettingController::class, 'balance'])->name('recharge.settings.balance');

    Route::get('/recharges', [RechargeAdminController::class, 'index'])->name('recharge.index');
    Route::post('/recharges/{recharge}/success', [RechargeAdminController::class, 'markSuccess'])->name('recharge.success');
    Route::post('/recharges/{recharge}/failed', [RechargeAdminController::class, 'markFailed'])->name('recharge.failed');
    Route::post('/recharges/{recharge}/reject', [RechargeAdminController::class, 'rejectSuccess'])->name('recharge.reject');

    Route::get('/welcome-offer', [WelcomeOfferAdminController::class, 'edit'])->name('welcome-offer.edit');
    Route::post('/welcome-offer', [WelcomeOfferAdminController::class, 'update'])->name('welcome-offer.update');
    Route::post('/welcome-offer/grant', [WelcomeOfferAdminController::class, 'grant'])->name('welcome-offer.grant');
    Route::get('/typing-job/settings', [TypingJobSettingsAdminController::class, 'edit'])->name('typing-job.settings.edit');
    Route::post('/typing-job/settings', [TypingJobSettingsAdminController::class, 'update'])->name('typing-job.settings.update');
    Route::get('/typing-job/history', [TypingJobAdminController::class, 'index'])->name('typing-job.index');

    Route::get('/users', [AdminUserController::class, 'index'])->name('users');
    Route::get('/users/withdraw-hold', [AdminUserController::class, 'withdrawHoldLookup'])->name('users.withdraw-hold.index');
    Route::get('/users/{id}/edit', [AdminUserController::class, 'edit'])->name('users.edit');
    Route::get('/users/{id}/withdraw-hold', [AdminUserController::class, 'editWithdrawHold'])->name('users.withdraw-hold.edit');
    Route::post('/users/{id}/withdraw-hold', [AdminUserController::class, 'updateWithdrawHold'])->name('users.withdraw-hold.update');
    Route::post('/users/{id}/update', [AdminUserController::class, 'update'])->name('users.update');
    Route::post('/users/{id}/ban', [AdminUserController::class, 'ban'])->name('users.ban');
    Route::post('/users/{id}/unban', [AdminUserController::class, 'unban'])->name('users.unban');
    Route::post('/users/{user}/activate', [AdminUserController::class, 'activate'])->name('users.activate');

    Route::get('/users/banned', [AdminUserController::class, 'bannedUsers'])->name('users.banned');
    Route::get('/users/inactive', [AdminUserController::class, 'inactiveUsers'])->name('users.inactive');
    Route::get('/active-users', [AdminUserController::class, 'activeUsers'])->name('users.active');

    Route::get('/users/{id}/message', [AdminUserController::class, 'showMessageForm'])->name('users.sendMessageForm');
    Route::post('/users/{id}/send-message', [AdminUserController::class, 'sendMessage'])->name('users.sendMessage');

    Route::post('/users/{id}/login', [\App\Http\Controllers\Admin\UserController::class, 'loginAsUser'])
        ->name('users.login')
        ->middleware('admin.impersonate.password');

    Route::get('/fb/dashboard', [FbAdminController::class, 'dashboard'])->name('fb.dashboard');
    Route::get('/fb/settings', [FbAdminController::class, 'settings'])->name('fb.settings');
    Route::post('/fb/settings', [FbAdminController::class, 'saveSettings'])->name('fb.settings.save');
    Route::get('/fb/submissions/export', [FbAdminController::class, 'export'])->name('fb.submissions.export');
    Route::get('/fb/submissions/{status}', [FbAdminController::class, 'showByStatus'])->name('fb.submissions.status');
    Route::post('/fb/submissions/bulk-action', [FbAdminController::class, 'bulkAction'])->name('fb.submissions.bulk-action');
    Route::post('/fb/submission/{id}/status', [FbAdminController::class, 'updateStatus'])->name('fb.submissions.update-status');
    Route::get('/fb/submission/{id}/status/{status}', [FbAdminController::class, 'changeStatus'])->name('fb.submissions.change-status');
    Route::get('/fb/export-processing-submissions', [FbAdminController::class, 'exportProcessing'])->name('fb.submissions.export.processing');

});

Route::middleware(['auth'])->group(function () {
    Route::get('/recharge', [UserRechargeController::class, 'index'])
        ->name('user.recharge.index');

    Route::post('/recharge/submit', [UserRechargeController::class, 'submit'])
        ->name('user.recharge.submit');

    Route::get('/recharge/history', [UserRechargeController::class, 'history'])
        ->name('user.recharge.history');

    Route::get('/recharge/{id}', [UserRechargeController::class, 'show'])
        ->whereNumber('id')
        ->name('recharge.show');
    Route::post('/recharge/{id}/refresh', [DrivePackController::class, 'refreshStatus'])
        ->whereNumber('id')
        ->name('recharge.refresh');
});
