<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Artisan;
use App\Http\Controllers\frontend\FrontendController;
use App\Http\Controllers\auth\AuthController;
use App\Http\Controllers\cart\CartController;
use App\Http\Controllers\order\OrderController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\OrdersController;
use App\Http\Controllers\Admin\LoginController; 
use App\Http\Controllers\Admin\ReturnController;
use App\Http\Controllers\Admin\UploadContoller;
use App\Http\Controllers\Admin\CustomerContoller;


Route::controller(FrontendController::class)->group(function(){
    Route::get('/','home')->name('home');
    Route::get('/view/{id}','viewproduct')->name('viewproduct');
    Route::get('/product-stock/{id}','getStock')->name('product.stock');
    Route::get('/category','category')->name('category');
    Route::get('/categoryproducts/{id}','categoryofproducts')->name('categoryproducts');
    Route::get('/products','products')->name('products');
    Route::any('/product','product')->name('product');
    Route::get('/hotsalling','hotsalling')->name('hotsalling');
    Route::get('/newarivel','newarivel')->name('newarivel');
    Route::get('/returnPloicy','returnPloicy')->name('returnPloicy');
   
});
Route::controller(CartController::class)->group(function(){
    Route::get('/addtocart/{id}','addtocart')->name('addtocart');
    Route::post('/addtomycart/{id}','addtomycart')->name('addtomycart');
    Route::get('/addtomywishlist/{id}','addtomywishlist')->name('addtomywishlist');

    Route::get('/mycart','mycart')->name('mycart');
    Route::get('/mycartitem','mycartitem')->name('mycartitem');

    Route::get('/mywishlist','mywishlist')->name('mywishlist');
    Route::get('/remove_wish/{id}','remove_wish')->name('remove_wish');

    
    Route::get('/remove/{id}','remove_item')->name('remove');
    Route::get('/update_add/{id}','update_item_add')->name('update_item_add');
    Route::get('/update_sub/{id}','update_item_sub')->name('update_item_sub');

    Route::get('/address','address')->name('address');
    Route::post('/add_address','add_address')->name('add_address');
    Route::post('/select_payment','select_payment')->name('select_payment');
    Route::post('/payment', 'checkout')->name('payment.checkout');
    Route::post('/checkout-confirm','checkoutConfirm')->name('Checkout-confirm');
    Route::post('/paymentStatus', 'paymentStatus')->name('paymentStatus');

    Route::post('/cart/show-cart-modal', 'showCartModal')->name('cart.showCartModal');
    Route::post('/cart/addtocarts', 'CartController@addToCarts')->name('cart.addToCarts');
    

});
Route::controller(AuthController::class)->group(function(){
    Route::get('/login','show_login')->name('login');
    Route::post('/login','Login')->name('login');
    Route::get('/logout','logout')->name('logout');

    Route::get('/register','show_register')->name('register');
    Route::post('/register','register')->name('register');
});
Route::controller(OrderController::class)->group(function(){
    Route::get('/order_return/{id}', 'order_return')->name('order_return');
    Route::get('/myOrder','myOrder')->name('myOrder');
    Route::get('/order-confirmed', 'order_confirmed')->name('order_confirmed');
    Route::post('/cancel_order', 'cancel_order')->name('cancel_order');
    Route::get('/customer_refund_request_add', 'customer_refund_request_add')->name('customer_refund_request_add');
    Route::get('/customer_return', 'customer_return')->name('customer_return'); 
    Route::get('/myOrder_detail/{id}', 'myOrder_detail')->name('myOrder_detail'); 
});


//admin contollers
Route::prefix('admin')->name('admin.')->group(function () {
    // Only guests can access login page
    Route::middleware('guest:admin')->group(function () {
        Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
        Route::post('/login', [LoginController::class, 'login'])->name('login.submit');
    });

    // Only authenticated admins can access dashboard and logout
    Route::middleware('auth:admin')->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
        Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
        Route::get('/product-list', [ProductController::class,'productlist'])->name('product.list');
        Route::get('/new-product', [ProductController::class,'newproduct'])->name('new.product');
        Route::post('/upload-product', [ProductController::class,'upload_product'])->name('product.upload');
        Route::post('/product/add-more-choice-option',[ProductController::class,'add_more_choice_option'])->name('product.add-more-choice-option');
        Route::post('/products/sku_combination', [ProductController::class,'sku_combination'])->name('products.sku_combination');
        Route::post('/products/sku_combination_edit', [ProductController::class,'sku_combination_edit'])->name('products.sku_combination_edit');
        Route::post('/products/add-more-choice-option', [ProductController::class,'add_more_choice_option'])->name('products.add-more-choice-option');
        Route::get('products/{id}/edit', [ProductController::class, 'updateproduct'])->name('products.edit');
        Route::put('products/{id}', [ProductController::class, 'update'])->name('products.update');

        
        Route::post('products/delete', [ProductController::class, 'delete'])->name('products.delete');
        Route::get('products/togglePublished', [ProductController::class, 'togglePublished'])->name('products.togglePublished');



      Route::get('/order-new', [OrdersController::class,'ordernew'])->name('Order.new');
      Route::get('/order-all', [OrdersController::class,'order_all'])->name('Order.all');
      Route::get('/order-detail/{id}', [OrdersController::class,'orderdetail'])->name('Order.detail');
      Route::get('/order/{id}/print', [OrdersController::class, 'print'])->name('order.print');
      Route::post('/order/{id}/confirm', [OrdersController::class, 'confirm'])->name('order.confirm');
      Route::post('/order/{id}/cancel', [OrdersController::class, 'cancel'])->name('order.cancel');


      Route::get('/customer-list', [CustomerContoller::class,'customerlist'])->name('customer.list');

      
        Route::get('/all-files', [UploadContoller::class, 'all'])->name('all.files');
        Route::post('/products/all-uploads', [UploadContoller::class, 'uploadImages'])->name('all.uploads');
    });

});







