<?php

use App\Http\Controllers\admin\adminController;
use App\Http\Controllers\admin\bannerController;
use App\Http\Controllers\admin\categoryController;
use App\Http\Controllers\admin\developer\developerController;
use App\Http\Controllers\admin\koombiyoreportController;
use App\Http\Controllers\admin\ordersController;
use App\Http\Controllers\admin\productController;
use App\Http\Controllers\admin\revenueController;
use App\Http\Controllers\admin\shippingzoneController;
use App\Http\Controllers\admin\systemController;
use App\Http\Controllers\admin\userController;
use App\Http\Controllers\admin\news\newsController;
use App\Http\Controllers\admin\event\eventController;
use App\Http\Controllers\admin\reviewController;
use App\Http\Controllers\CodController;
use App\Http\Controllers\KokoPaymentController;
use App\Http\Controllers\MintpayController;
use App\Http\Controllers\web\home\aboutusController;
use App\Http\Controllers\web\home\dealController;
use App\Http\Controllers\web\home\allproductsController;
use App\Http\Controllers\web\home\cartController;
use App\Http\Controllers\web\home\contactusController;
use App\Http\Controllers\web\home\filterController;
use App\Http\Controllers\web\home\ForgotPasswordController;
use App\Http\Controllers\web\home\gridController;
use App\Http\Controllers\web\home\homeController;
use App\Http\Controllers\web\home\loginController;
use App\Http\Controllers\web\home\myprofileController;
use App\Http\Controllers\web\home\orderController;
use App\Http\Controllers\web\home\registerController;
use App\Http\Controllers\web\home\singleproductController;
use App\Http\Controllers\web\home\wishlistController;
use App\Http\Controllers\web\home\newseventController;
use App\Http\Controllers\web\SocialShareButtonsController;
use App\Http\Controllers\web\policyController;

use App\Http\Controllers\PaymentController;
use App\Http\Controllers\PaymentdataController;
use App\Livewire\CartItem;
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 and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/


// ////////////////////////////////////////////////////////Admin panel routes////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Route::get('/admin/login', [adminController::class, 'login_index'])->name('american.plastic.admin.login');
Route::post('/admin/login/form-data', [adminController::class, 'login'])->name('american.plastic.superadmin.login.form');

Route::middleware(['auth', 'role:superadmin|Supervisor|Writer|Admin|HR|dev'])->group(function () {
    Route::get('/admin/dashboard', [adminController::class, 'admin_dashboard'])->name('american.plastic.admin.dashboard');
    Route::get('/admin/dashboard/log-out', [adminController::class, 'admin_logout'])->name('american.plastic.admin.log.out');
    Route::get('/admin/dashboard/download-report', [adminController::class, 'traffic_report'])->name('american.plastic.admin.download.traffic');

    /////admin section///////
    Route::get('/admin/add-admin-section', [adminController::class, 'admin_section'])->name('american.plastic.admin.create.admin');//admin section view
    Route::post('/admin/create/new-admin', [adminController::class, 'create_admin'])->name('ajax.create.new.admin');//////create new admin
    Route::get('/admin/get-admin-data', [adminController::class, 'admindata_get'])->name('admin.admindata.get');//admin data fetch
    Route::match(['get', 'post'], '/check/{userId}', [adminController::class, 'check_role'])->name('check.roles');////get roles
    Route::match(['get', 'post'], '/assign-role/{userId}', [adminController::class, 'fetchRoles'])->name('fetch.roles');///fetch role
    Route::get('/get-permission/{userId}', [adminController::class, 'getPermisssion'])->name('get.permission');//get all permission
    Route::post('/assign-permission', [adminController::class, 'assignPermission'])->name('admin.assign.permission');//assign permission
    Route::match(['get', 'post'], '/delete-user/{userId}', [adminController::class, 'deleteuser'])->name('delete.user.admin');////delete admin user
//////admin section//////

    /////////category section////////
    Route::get('/admin/add-category-section', [categoryController::class, 'category_section'])->name('american.plastic.admin.category');//category section view
    Route::post('/admin/create/category', [categoryController::class, 'create_category'])->name('admin.create.new.category');//add category
    Route::get('/admin/get-category-data', [categoryController::class, 'get_category'])->name('admin.category.get');//category data get
    Route::get('/admin/edit-category-data{id}', [categoryController::class, 'edit_category'])->name('admin.category.edit');//category data get
    Route::post('/admin/update/category', [categoryController::class, 'update_category'])->name('ajax.edit.exsiting.category');//update category
    Route::post('/admin/delete/category/{categoryId}', [categoryController::class, 'delete_category'])->name('delete.category');//delete category

    Route::get('/admin/category-banner/{id}', [categoryController::class, 'banner_index'])->name('category.banner');///category banner page
    Route::post('/admin/adde/category/banner', [categoryController::class, 'addcategory_banner'])->name('admin.add.category.banner');//add category banner

    Route::post('/admin/remove/category/banner', [categoryController::class, 'removecategory_banner'])->name('admin.remove.category.banner');//add category banner
/////////category section/////////

    /////////product section///////
    Route::get('/admin/product-order-zero', [productController::class, 'productZero'])->name('american.plastic.zero.admin.product');

    Route::get('/admin/add-product-section', [productController::class, 'product_section'])->name('american.plastic.admin.product');/////////////product section view////////
    Route::post('/admin/add/new/product', [productController::class, 'add_product'])->name('admin.add.new.product');//////add product//////
    Route::get('/admin/get-product-data', [productController::class, 'get_products'])->name('admin.product.data.get');///////products data get
    Route::get('/admin/edit-product-data{id}', [productController::class, 'edit_product'])->name('admin.product.edit');//edit product
    Route::post('/delete-image', [productController::class, 'delete_image'])->name('ajax.delete.exsiting.image');////delete product image
    Route::post('/admin/update/product', [productController::class, 'update_product'])->name('ajax.update.exsiting.product');////delete product image
    Route::post('/admin/delete/product/{productId}', [productController::class, 'delete_product'])->name('delete.product');//delete product
    Route::post('/admin/restore/product/{productId}', [productController::class, 'restore_product'])->name('restore.product');//restore product


    Route::get('/admin/product/out-of-stock', [productController::class, 'out_index'])->name('american.plastic.admin.product.out.of.stock');/////////////product out of stock////////
    Route::get('/admin/product/productcolor/out-of-stock', [productController::class, 'color_out_index'])->name('american.plastic.admin.product.color.out.of.stock');
    Route::get('/admin/product/get/productcolor/out-of-stock', [productController::class, 'get_product_color_data'])->name('american.plastic.admin.product.get.productcolor.out.of.stock.live');
    Route::get('/admin/product/get/productcolor/out-of-stock/report', [productController::class, 'get_product_color_data_report'])->name('american.plastic.admin.product.get.productcolor.out.of.stock.live.report');
    Route::get('/admin/product/get/productcolor/only/out-of-stock/report', [productController::class, 'get_outofproduct_color_data_report'])->name('american.plastic.admin.product.get.productcolor.only.out.of.stock.live.report');

    Route::get('/admin/all/product/out-of-stock', [productController::class, 'all_outof_stock'])->name('american.plastic.admin.product.get.out.of.stock.live');/////////////product out of stock////////

    //////////product summary////////////
    Route::get('/admin/products-summary', [productController::class, 'product_summary'])->name('american.plastic.admin.product.summary');
    Route::get('/admin/products-summary-data', [productController::class, 'products_data'])->name('american.plastic.admin.product.get.summary');
    Route::get('/admin/product/addcolor', [productController::class, 'addColor'])->name('admin.product.addcolor');
    Route::post('/admin/add/product/color', [productController::class, 'add_productcolor'])->name('admin.add.product.color');

    Route::get('admin/product/color/data/get/{productId}', [productController::class, 'product_color_data'])->name('admin.product.color.data.get');
    Route::post('/admin/delete/color/{id}', [productController::class, 'delete_color'])->name('delete.colorid');

    Route::get('/admin/edit/color/{id}', [productController::class, 'edit_color'])->name('edit.colorid');
    Route::post('/admin/updqate/color', [productController::class, 'update_color'])->name('ajax.update.exsiting.color');

    Route::get('/products/summary/export', [productController::class, 'exportProducts'])->name('products.summary.export');

    ///////product section////////



    /////////shipping section////////////
    Route::get('/admin/index/shipping-zone', [shippingzoneController::class, 'shiiping_index'])->name('american.plastic.admin.index.shipping.zone');///////shipping section
    Route::post('/admin/add/shipping/zone', [shippingzoneController::class, 'add_shippingzone'])->name('admin.create.new.shipping.zone');///add shipping zone
    Route::get('/admin/index/get-shipping-zone', [shippingzoneController::class, 'shiiping_zone_all'])->name('admin.shipping.zone.get');
    Route::get('/admin/edit-shipping-data{id}', [shippingzoneController::class, 'edit_shipping'])->name('admin.shipping.edit');//shipping data get
    Route::post('/admin/update/shipping', [shippingzoneController::class, 'update_shipping'])->name('ajax.update.exsiting.shipping.service');
    Route::post('/admin/delete/shipping/{shippingid}', [shippingzoneController::class, 'delete_shipping'])->name('delete.shipping');//delete category

    ////////////Area/////////////
    Route::get('/admin/index/shipping-area', [shippingzoneController::class, 'area_index'])->name('american.plastic.admin.index.shipping.area');
    Route::post('/admin/add/shipping/area', [shippingzoneController::class, 'add_area'])->name('admin.create.new.shipping.area');
    Route::get('/admin/index/get-area', [shippingzoneController::class, 'shiiping_area_all'])->name('admin.shipping.area.get');
    Route::post('/admin/delete/area/{areaid}', [shippingzoneController::class, 'delete_area'])->name('delete.area');
    ///////////Area/////////////
/////////shipping section/////////


    ////////////////order section///////////////
    Route::get('/admin/index/order-section', [ordersController::class, 'order_index'])->name('american.plastic.admin.all.order');
    Route::get('/admin/index/get-all-orders', [ordersController::class, 'orders_get'])->name('american.plastic.admin.orders.get');
    Route::post('/admin/cancel-order', [ordersController::class, 'cancel_order'])->name('american.plastic.admin.cancel.order');
    Route::post('/admin/cancel-request', [ordersController::class, 'request_cancel'])->name('american.plastic.admin.reject.request');
    Route::get('admin/order/edit', [ordersController::class, 'editorder'])->name('admin.order.edit');
    Route::post('/admin/order-update', [ordersController::class, 'order_update'])->name('order.update.details');
    Route::get('/admin/index/order-history', [ordersController::class, 'order_history'])->name('american.plastic.admin.order.history');
    Route::get('/admin/index/order.filter', [ordersController::class, 'get_order_data'])->name('american.plastic.admin.filter.order');

    Route::get('/admin/index/pending-orders', [ordersController::class, 'pending_orders_index'])->name('american.plastic.admin.pending.orders');
    Route::get('/admin/index/get-pending-orders', [ordersController::class, 'pending_orders_get'])->name('american.plastic.admin.pending.orders.get');
    Route::get('/admin/order/pending-details', [ordersController::class, 'pending_order_details'])->name('admin.order.pending.details');

    Route::match(['get', 'post'], '/admin/order/report', [ordersController::class, 'order_report_dashboard'])->name('american.plastic.admin.order.report.dashboard');
    Route::match(['get', 'post'], '/admin/order/download/report', [ordersController::class, 'downloadReport'])->name('admin.orders.download.report');

    ///////////////order section////////////////

    //////////////user section//////////////////
    Route::get('/admin/index/user-section', [userController::class, 'user_index'])->name('american.plastic.admin.get.users');
    Route::get('/admin/index/users', [userController::class, 'get_user'])->name('american.plastic.admin.users.get.all');
    Route::post('/admin/suspend-user', [userController::class, 'suspend_account'])->name('american.plastic.admin.set.user.suspend');
    Route::post('/admin/recover-user-account', [userController::class, 'recover_account'])->name('american.plastic.admin.recover.account');
    Route::get('/admin/user/export', [userController::class, 'exportUser'])->name('users.export');

    /////////////user section///////////////////


    //////////////////revenue/////////////////////
    Route::get('/admin/index/revenue-section', [revenueController::class, 'revenue_index'])->name('american.plastic.admin.revenue');


    //////////news////////////////////////////
    Route::get('/admin/news', [newsController::class, 'news_index'])->name('american.plastic.admin.news.section');
    Route::post('/admin/add/news', [newsController::class, 'add_news'])->name('admin.add.new.news');
    Route::get('/admin/get/all/news', [newsController::class, 'get_news'])->name('admin.news.get');
    Route::get('/admin/edit-news-data{id}', [newsController::class, 'edit_news'])->name('admin.news.edit');
    Route::post('/admin/update/news', [newsController::class, 'update_news'])->name('ajax.update.exsiting.news');
    Route::post('/admin/delete/news/{newsid}', [newsController::class, 'delete_news'])->name('delete.news');
    //////////news///////////////////////////

    ///////reviews//////////////

    Route::get('/admin/product/review', [reviewController::class, 'index'])->name('american.plastic.admin.product.reviews');
    Route::get('/admin/product/get-review', [reviewController::class, 'get_reviews'])->name('american.plastic.admin.users.review.get.all');
    Route::post('/admin/active-user-review', [reviewController::class, 'active_review'])->name('american.plastic.admin.active.review');
    Route::post('/admin/deactive-user-review', [reviewController::class, 'deactive_review'])->name('american.plastic.admin.deactive.review');
    Route::post('/admin/delete-user-review', [reviewController::class, 'deleted_review'])->name('american.plastic.admin.delete.review');


    //////////events///////////////////////////
    Route::get('/admin/event', [eventController::class, 'event_index'])->name('american.plastic.admin.event.section');
    Route::post('/admin/add/event', [eventController::class, 'add_event'])->name('admin.add.new.event');
    Route::get('/admin/get/all/event', [eventController::class, 'get_event'])->name('admin.event.get');
    Route::get('/admin/edit-event-data{id}', [eventController::class, 'edit_event'])->name('admin.event.edit');
    Route::get('/admin/set-event-past{id}', [eventController::class, 'set_event_past'])->name('admin.event.set.past');
    Route::post('/admin/update/event', [eventController::class, 'update_event'])->name('ajax.update.exsiting.event');
    Route::post('/admin/delete/event/{eventid}', [eventController::class, 'delete_event'])->name('delete.event');
    ////////////////system log///////////////////
    Route::get('/admin/system/log-protected', [systemController::class, 'system_index'])->name('american.plastic.admin.system.log');

    /////////koombiyoreport///////////
    Route::get('/admin/koombiyo-report', [koombiyoreportController::class, 'koombiyodashboard'])->name('american.plastic.admin.koombiyo.report');
    Route::post('/admin/koombiyo/download', [koombiyoreportController::class, 'downloadReport'])->name('admin.koombiyo.download');
    ////////////////banner//////////////////////
    Route::get('/admin/index/banner-section', [bannerController::class, 'banner_Index'])->name('american.plastic.admin.update.home.banner');
    Route::post('/admin/banner-update', [bannerController::class, 'update_banner'])->name('admin.add.banner');
    Route::post('/admin/add-hero-slide', [bannerController::class, 'add_hero_slide'])->name('admin.add.hero.slide');
    Route::post('/admin/delete-hero-slide/{id}', [bannerController::class, 'delete_hero_slide'])->name('admin.delete.hero.slide');

    Route::get('/admin/product/deactive', [productController::class, 'deactive'])->name('admin.product.deactive');
    Route::get('/admin/product/active', [productController::class, 'active'])->name('admin.product.activate');

    Route::get('/error', function () {
        return redirect()->route('admin.developer.logs', ['tab' => 'monitor']);
    })->name('american.plastic.admin.login.error');

    Route::prefix('developer')->group(function () {
        Route::get('dashboard', [developerController::class, 'developerDashboard'])->name('admin.developer.dashboard');
        Route::get('dashboard-alias', [developerController::class, 'developerDashboard'])->name('admin.dev.dashboard');
        Route::get('logs', [developerController::class, 'developerDashboard'])->name('admin.developer.logs');
        Route::get('logs/live-data', [developerController::class, 'getLiveData'])->name('admin.developer.logs.live-data');
        Route::post('clear-log', [developerController::class, 'clearLog'])->name('admin.developer.clear-log');
        Route::get('logs/logout', [developerController::class, 'logoutLogs'])->name('admin.developer.logs.logout');
    });
    // Voucher Management
    Route::resource('admin/vouchers', App\Http\Controllers\admin\VoucherController::class)->names([
        'index' => 'admin.vouchers.index',
        'create' => 'admin.vouchers.create',
        'store' => 'admin.vouchers.store',
        'edit' => 'admin.vouchers.edit',
        'update' => 'admin.vouchers.update',
        'destroy' => 'admin.vouchers.destroy',
    ]);
    Route::post('admin/vouchers/{id}/send-mail', [App\Http\Controllers\admin\VoucherController::class, 'sendVoucherMail'])->name('admin.vouchers.send-mail');
    // vouchers/apply moved to public routes

    // Analytics Dashboard
    Route::match(['get', 'post'], 'admin/analytics', [App\Http\Controllers\admin\AnalyticsController::class, 'index'])->name('admin.analytics.index');
    Route::get('admin/analytics/products-report', [App\Http\Controllers\admin\AnalyticsController::class, 'productsReport'])->name('admin.analytics.products-report');
    Route::get('admin/analytics/products-report/export', [App\Http\Controllers\admin\AnalyticsController::class, 'productsReportExport'])->name('admin.analytics.products-report.export');
    Route::get('admin/analytics/download-pdf', [App\Http\Controllers\admin\AnalyticsController::class, 'downloadPdf'])->name('admin.analytics.download-pdf');

    // Tax Report
    Route::get('admin/tax-report', [App\Http\Controllers\admin\TaxReportController::class, 'index'])->name('admin.tax-report');
    Route::post('admin/tax-report/update-base', [App\Http\Controllers\admin\TaxReportController::class, 'updateTaxBase'])->name('admin.tax-report.update-base');
    Route::post('admin/tax-report/update-rate', [App\Http\Controllers\admin\TaxReportController::class, 'updateTaxRate'])->name('admin.tax-report.update-rate');
    Route::get('admin/tax-report/download', [App\Http\Controllers\admin\TaxReportController::class, 'download'])->name('admin.tax-report.download');

    // Dev Chat Support
    Route::get('admin/dev-chat', [App\Http\Controllers\admin\DevChatController::class, 'index'])->name('admin.dev-chat');
    Route::post('admin/dev-chat/send', [App\Http\Controllers\admin\DevChatController::class, 'store'])->name('admin.dev-chat.send');

    // Invoices
    Route::get('admin/invoices', [App\Http\Controllers\admin\InvoiceController::class, 'index'])->name('admin.invoices.index');
    Route::get('admin/invoices/{id}/download', [App\Http\Controllers\admin\InvoiceController::class, 'download'])->name('admin.invoices.download');

    // CSR Recycling Management
    Route::get('admin/csr', [App\Http\Controllers\admin\RecyclingRequestController::class, 'index'])->name('admin.csr.index');
    Route::get('admin/csr/data', [App\Http\Controllers\admin\RecyclingRequestController::class, 'getData'])->name('admin.csr.data');
    Route::post('admin/csr/update-status', [App\Http\Controllers\admin\RecyclingRequestController::class, 'updateStatus'])->name('admin.csr.update');
    Route::get('admin/csr/export', [App\Http\Controllers\admin\RecyclingRequestController::class, 'export'])->name('admin.csr.export');
    //////////////////////////////////////////////////////////Admin panel routes////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
});

Route::get('/home', [homeController::class, 'index'])->name('american.plastic.web');/////////////homepage view////////
Route::get('/', [homeController::class,'coming_soon'])->name('american.plastic.comingsoon');

/////////////////////////////////////////////////////////Website routes/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Route::get('/login', [loginController::class, 'login'])->name('american.plastic.login');///////user login////////
Route::post('/user-register', [registerController::class, 'user_register'])->name('american.plastic.user.register');//////user register//////
Route::get('account/verify/{token}', [registerController::class, 'verifyAccount'])->name('user.verify');//////////verify email///////////
Route::post('/user-login', [loginController::class, 'user_login'])->name('american.plastic.user.login');

// Voucher Apply (Public)
Route::post('vouchers/apply', [App\Http\Controllers\admin\VoucherController::class, 'applyVoucher'])->name('vouchers.apply');
Route::post('/check-email', function (Illuminate\Http\Request $request) {
    $exists = \App\Models\User::where('email', $request->email)->exists();
    return response()->json(['exists' => $exists]);
})->name('check.email');


////////////////////products page/////////////////
Route::get('/plastic-products', [allproductsController::class, 'all_products'])->name('american.plastic.products');//load all products
Route::get('/categories/product/{name}', [singleproductController::class, 'viewproduct'])->name('american.plastic.web.product.details');//view product
Route::post('/product/add-to-cart/{id}/{quantity}', [singleproductController::class, 'product_addtocart'])->name('american.plastic.web.product.addtocart');
Route::match(['get', 'post'], '/american-plastic/product-filter', [allproductsController::class, 'all_products'])->name('american.plastic.web.product.price.filter');
Route::match(['get', 'post'], '/american-plastic/product-search', [allproductsController::class, 'search_products'])->name('american.plastic.web.search.product');
Route::get('plastic/{id}/{selectedcolor}', [singleproductController::class, 'view_product_color'])->name('american.plastic.web.product.details.color');
////////////////////products page/////////////////



///////view categories products/////////
Route::get('/products/{name}', [allproductsController::class, 'view_from_categories'])->name('american.plastic.web.view.categories.product');//load categories products
//////view categories products/////////

///////deals//////////////////
Route::get('/deals', [dealController::class, 'deal_index'])->name('american.plastic.deals.products');

///cart
Route::match(['get', 'post'], '/american-plastic/view-cart', [cartController::class, 'view_cart'])->name('american.plastic.web.view.user.cart');
Route::post('/update_cart', [cartController::class, 'updateCart'])->name('update_cart');//cart update
Route::match(['get', 'post'], '/american-plastic/remove-cart-item/{id}', [cartController::class, 'remove_cart'])->name('american.plastic.web.remove.cart.item');
Route::match(['get', 'post'], '/american-plastic/cart-checkout', [cartController::class, 'cart_checkout'])->name('american.plastic.web.cart.checkout');


////cart

///////wishlist///////
Route::match(['get', 'post'], '/american-plastic/addto-wishlist/{id}', [wishlistController::class, 'add_to_wishlist'])->name('american.plastic.web.addto.wishlist');
Route::match(['get', 'post'], '/american-plastic/wishlist', [wishlistController::class, 'mywishlist'])->name('american.plastic.web.mywishlist');
Route::match(['get', 'post'], '/american-plastic/wishlist-remove/{id}', [wishlistController::class, 'remove_wishlist'])->name('american.plastic.web.wishlist.remove');

////////filter////////

//////////user review/////////
// web.php
Route::post('/submit-review', [singleproductController::class, 'store_review'])->name('review.store');



//////my profile////
Route::get('/my-profile', [myprofileController::class, 'profilepage'])->name('american.plastic.web.myprofile');
Route::post('/user-address/update', [myprofileController::class, 'user_address'])->name('american.plastic.web.user.address');
Route::post('/user-profile/data/update', [myprofileController::class, 'user_profiledata'])->name('american.plastic.web.user.profile.data');
Route::match(['get', 'post'], '/upload-profile-pic', [myprofileController::class, 'upload_profile_pic'])->name('american.plastic.user.upload.profile.pic');
Route::match(['get', 'post'], '/delete-profile-pic', [myprofileController::class, 'delete_profile_pic'])->name('american.plastic.user.remove.profile.pic');
Route::get('user/logout', [myprofileController::class, 'user_logout'])->name('american.plastic.web.user.logout');


/////my profile/////


///////////////////order/////////////////////////
Route::match(['get', 'post'], '/order-checkout', [orderController::class, 'checkout_page'])->name('american.plastic.web.order.checkout');
Route::match(['get', 'post'], '/get-shipping/details/{selectedvalue}', [orderController::class, 'checkzone'])->name('zone.check');

Route::match(['get', 'post'], '/order-confirmed', [orderController::class, 'order_confirmed'])->name('american.plastic.web.order.confirmed');
Route::match(['get', 'post'], '/order-unsuccessful', [orderController::class, 'order_unsucessful'])->name('web.home.checkout.unsuccess');
Route::get('view/order/{id}', [orderController::class, 'order_view'])->name('american.plastic.view.order');

Route::match(['get', 'post'], '/cod', [CodController::class, 'order_confirmed_cod'])->name('american.plastic.web.order.cod.confirmed');
Route::match(['get', 'post'], '/points-checkout', [CodController::class, 'order_confirmed_points'])->name('american.plastic.web.order.points.confirmed');


Route::get('/orders/search', function () {
    $user = Auth::user();
    $search = request()->input('search');

    $orderdata = App\Models\Order::where('userid', $user->id)
        ->when($search, function ($query) use ($search) {
            $query->where(function ($q) use ($search) {
                $q->where('order_id', 'like', '%' . $search . '%')
                    ->orWhereHas('productData', function ($productQuery) use ($search) {
                        $productQuery->where('product_name', 'like', '%' . $search . '%');
                    });

            });
        })
        ->orderBy('created_at', 'desc')
        ->paginate(5);


    return view('web.home.partials.orders_list', ['orderdata' => $orderdata]);
})->name('american.plastic.orders.search');


/////////////cartorder//////////////////
Route::match(['get', 'post'], 'cart-checkout/get-billing-data', [orderController::class, 'checkout_cart_all'])->name('american.plastic.web.cart.checkout.billing.data');
////////////cartorder//////////////////

/////////cancel order/////////
Route::match(['get', 'post'], '/cancel-order', [orderController::class, 'cancel_order'])->name('american.plastic.web.cancel.order');
////////cancel order////////
///////////////////order////////////////////////


/////////////////newsevent//////////////////////
Route::match(['get', 'post'], '/news-and-events', [newseventController::class, 'newsevent'])->name('american.plastic.web.news.and.event');
Route::match(['get', 'post'], '/event/{id}', [newseventController::class, 'view_event'])->name('web.home.event.view');
Route::match(['get', 'post'], '/news/{id}', [newseventController::class, 'view_news'])->name('web.home.news.view');


//////////////about us/////////////
Route::match(['get', 'post'], '/about-us', [aboutusController::class, 'about_us'])->name('american.plastic.web.about.us');

/////////////contact us///////////
Route::match(['get', 'post'], '/contact-us', [contactusController::class, 'contact_us'])->name('american.plastic.web.contact.us');
Route::match(['get', 'post'], '/contactus-submit-form', [contactusController::class, 'form_submit'])->name('american.plastic.web.contact.us.form');

////////////buy now//////////////
Route::match(['get', 'post'], '/buy-now', [gridController::class, 'index'])->name('american.plastic.web.buy.now');


///////////////forget password///////////
Route::get('forget-password', [ForgotPasswordController::class, 'showForgetPasswordForm'])->name('forget.password.get');
Route::post('forget-password', [ForgotPasswordController::class, 'submitForgetPasswordForm'])->name('forget.password.post');
Route::get('reset-password/{token}', [ForgotPasswordController::class, 'showResetPasswordForm'])->name('reset.password.get');
Route::post('reset-password', [ForgotPasswordController::class, 'submitResetPasswordForm'])->name('reset.password.post');


Route::post('/check-user-exist', [registerController::class, 'checkUserExist'])->name('american.plastic.user.exist');

/////social share///////////////
Route::get('/social-media-share/{id}', [SocialShareButtonsController::class, 'ShareWidget'])->name('web.social.share');

/////////policy/////////////////
Route::get('/privacy-policy', [policyController::class, 'privacy_policy'])->name('american.plastic.web.privacy.policy');
Route::get('/terms-and-conditions', [policyController::class, 'terms_and_conditions'])->name('american.plastic.web.terms.conditions');
Route::get('/return-policy', [policyController::class, 'return_policy'])->name('american.plastic.web.return.policy');


// CSR Recycling
Route::get('/csr', [App\Http\Controllers\web\CsrController::class, 'index'])->name('american.plastic.web.csr');
Route::middleware(['auth'])->group(function () {
    Route::post('/csr/submit', [App\Http\Controllers\web\CsrController::class, 'submitRequest'])->name('american.plastic.web.csr.submit');
    
    Route::post('/notifications/mark-all-read', function () {
        Auth::user()->notifications()->where('is_read', false)->update(['is_read' => true]);
        return response()->json(['success' => true]);
    })->name('notifications.mark-all-read');

    Route::post('/notifications/{id}/mark-read', function ($id) {
        $notification = Auth::user()->notifications()->findOrFail($id);
        $notification->update(['is_read' => true]);
        return response()->json(['success' => true]);
    })->name('notifications.mark-read');
});

////////subscriber////
Route::post('/newsletter', [homeController::class, 'subscriber_add'])->name('subscribe.user');

//////payment integration//////////
Route::post('/create-session', [PaymentController::class, 'createSession']);
Route::get('/next-page', [PaymentController::class, 'next_page'])->name('next.page');
Route::get('/verify-payment/{orderId}', [PaymentController::class, 'verifyPaymentStatus'])->name('payment.verify');
Route::get('/payment/success', [PaymentController::class, 'paymentSuccess'])->name('payment.success');
Route::get('/payment/callback', [PaymentController::class, 'handleCallback'])->name('payment.result');

Route::get('/cod/page', [CodController::class, 'cod_index'])->name('next.cod.page');


Route::prefix('koko')->name('koko.')->group(function () {
    Route::prefix('payment')->name('payment.')->group(function () {
        // Initiate payment (POST)
        Route::post('/initiate', [KokoPaymentController::class, 'initiatePayment'])
            ->name('initiate');

        // Payment success callback (GET)
        Route::get('/success', [KokoPaymentController::class, 'paymentSuccess'])
            ->name('success');

        // Payment cancellation (GET)
        Route::get('/cancel', [KokoPaymentController::class, 'paymentCancel'])
            ->name('cancel');

        // Payment gateway response/webhook (POST)
        Route::post('/response', [KokoPaymentController::class, 'paymentResponse'])
            ->name('response')
            ->withoutMiddleware(['web']); // If this is an API/webhook endpoint
    });
});

Route::post('/checkout/mintpay', [MintpayController::class, 'payWithMintpay'])->name('mintpay.checkout');
Route::get('/mintpay/success', [MintpayController::class, 'success'])->name('mintpay.success');
Route::get('/mintpay/fail', [MintpayController::class, 'fail'])->name('mintpay.fail');
Route::get('/checkzone/{selectedvalue}', [orderController::class, 'checkzone'])->name('zone.check');
Route::post('/get-koombiyo-cities', [orderController::class, 'get_cities'])->name('get.koombiyo.cities');
Route::get('/checkout-cart-all', [orderController::class, 'checkout_cart_all'])->name('checkout.cart.all');



/////////////////////////////////////////////////////////Website routes/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
