<?php

use App\Http\Controllers\Web\AddressController;
use App\Http\Controllers\Web\AuthController;
use App\Http\Controllers\Web\CartController;
use App\Http\Controllers\Web\NewsletterController;
use App\Http\Controllers\Web\OrderController;
use App\Http\Controllers\Web\ProductController;
use App\Http\Controllers\Web\ProfileController;
use App\Http\Controllers\Web\VisitorMessageController;
use App\Http\Controllers\Web\HomeController;
use App\Http\Controllers\Web\PageController;
use Illuminate\Support\Facades\Route;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;

/*
  |--------------------------------------------------------------------------
  | 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('language/{id}/{slug?}', 'LanguageController@details');

Route::group(['prefix' => LaravelLocalization::setLocale()], function () {

    Route::group(['middleware' => ['checkWebSiteEnabled', 'WebsiteVisitorCount']], function () {
        //Home
        Route::get('/', [HomeController::class,'index'])->name('web.home');
        Route::get('/aboutus', [PageController::class,'aboutus'])->name('web.aboutus');
        Route::get('/terms', [PageController::class,'terms'])->name('web.terms');
        Route::get('/policy', [PageController::class,'policy'])->name('web.policy');
        Route::resource('contactus', VisitorMessageController::class)->only(['index','store']);
        Route::get('/newsletter', [VisitorMessageController::class,'index']);
        Route::post('/newsletter', [NewsletterController::class,'store'])->name('web.newsletter');
        Route::resource ('cart',CartController::class)->only(['index','store','update','destroy']);
        Route::get('/calculate', [CartController::class,'calculate'])->name('web.cart.calculate');
        Route::get('/check/coupon', [CartController::class,'checkCoupon'])->name('web.check.coupon');

        Route::get('/search', [ProductController::class,'search'])->name('web.search');

        Route::group(['prefix' => 'product'], function () {
            Route::get('/{id}', [ProductController::class,'details'])->name('web.product.details');
            Route::get('/', [ProductController::class,'products'])->name('web.product');
        });
        Route::get('filter', [ProductController::class,'filter'])->name('web.filter');
        Route::get ('fetch/category',[ProductController::class,'fetchCategory'])->name('web.fetch.categories');

        Route::group(['prefix' => 'checkout'], function () {
            Route::get('/address',[OrderController::class,'address'])->name('web.checkout.address');
            Route::post('/address',[OrderController::class,'addressCheckout'])->name('web.checkout.addressing');
            Route::get('/way',[OrderController::class,'way'])->name('web.checkout.way');
            Route::post('/way',[OrderController::class,'wayCheckout'])->name('web.checkout.waying');
            Route::get('/order',[OrderController::class,'order'])->name('web.checkout.order');
            Route::post('/order',[OrderController::class,'orderCheckout'])->name('web.checkout.ordering');
            Route::get('/payment',[OrderController::class,'payment'])->name('web.checkout.payment');
        });
        Route::resource ('address',AddressController::class)->except(['show']);
        Route::get ('fetch/city',[AddressController::class,'fetchCity'])->name('web.fetch.cities');

        Route::group(['middleware' => ['GuestAuth']], function () {
            Route::group(['prefix' => 'login'], function () {
                Route::get('/', [AuthController::class,'login'])->name('web.login');
                Route::post('/', [AuthController::class,'loginCheck'])->name('web.login.check');
            });
            Route::group(['prefix' => 'regist'], function () {
                Route::get('/', [AuthController::class,'regist'])->name('web.regist');
                Route::post('/', [AuthController::class,'userStore'])->name('web.regist.store');
            });
            Route::group(['prefix' => 'forgetpassword'], function () {
                Route::get('/', [AuthController::class,'forgetpassword'])->name('web.forgetpassword');
                Route::post('/', [AuthController::class,'forgetpasswordCheck'])->name('web.forgetpassword.check');
            });
            Route::group(['prefix' => 'verify/code'], function () {
                Route::get('/', [AuthController::class,'verifyCode'])->name('web.verify.code');
                Route::post('/', [AuthController::class,'verifyCodeCheck'])->name('web.verify.code.check');
            });
            Route::group(['prefix' => 'resetpassword'], function () {
                Route::get('/', [AuthController::class,'resetpassword'])->name('web.resetpassword');
                Route::post('/', [AuthController::class,'resettingPassword'])->name('web.resetpassword.store');
            });
        });
        Route::group(['middleware' => ['AuthLogin']], function (){

            Route::get('/logout', [AuthController::class,'logout'])->name('web.logout');
            Route::group(['prefix' => 'profile'], function () {
                Route::get('/', [ProfileController::class,'profile'])->name('web.profile');
                Route::put('/', [ProfileController::class,'editProfile'])->name('web.profile.edit');
            });
            Route::get('/notification', [ProfileController::class,'notification'])->name('web.notification');
            Route::get('/order', [OrderController::class,'orders'])->name('web.order');
            Route::get('/order/{id}', [OrderController::class,'orderDetails'])->name('web.order.details');
            Route::post('/favorite', [ProductController::class,'favoriteProduct'])->name('web.favorite.store');
            Route::get('/favorite', [ProductController::class,'favorite'])->name('web.favorite');
            Route::post('/rate', [OrderController::class,'rate'])->name('web.rate');

        });

    });
});
