<?php

use Illuminate\Support\Facades\Route;
use App\Mail\MailtrapExample;
use App\Mail\VerifyCodeMail;
use Illuminate\Support\Facades\Mail;

/*
|--------------------------------------------------------------------------
| 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');
/**
* Localization Group
*/

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


    Route::get('/', 'HomeController@index');

	/**
	* Authentication routes , and Authentication user routs
	*/
	Auth::routes();

	// Route::get('/home', 'HomeController@index')->name('home');
	Route::get('/notify', 'LoopUserController@payForLoop');
	/**
	* Admin Routes
	*/
	Route::group([ 'prefix'=> 'admin', 'namespace' => 'Admin'], function () {

		Route::get('/login', 'LoginController@index');
		Route::post('/login', 'LoginController@authenticate')->name('admin_login');

		Route::group([ 'middleware' => ['admin_auth']], function () {
			Route::get('/', 'DashboardController@index')->name('dashboard');

			Route::post('/logout', 'LoginController@logout')->name('admin_logout');

			Route::group([ 'middleware' => ['checkRole']], function () {

                // PAGES ROUTES
                Route::put('/pages/restore/{id}', 'PageController@restore')->name('pages.restore');
                Route::put('/pages/restore', 'PageController@restoreAll')->name('pages.restoreAll');
                Route::delete('/pages', 'PageController@destroyAll')->name('pages.destroyAll');
                Route::get('/pages/grid', 'PageController@grid')->name('pages.grid');
                Route::resource('/pages', 'PageController');

                // LOOPS ROUTES
                Route::put('/loops/restore/{id}', 'LoopController@restore')->name('loops.restore');
                Route::put('/loops/restore', 'LoopController@restoreAll')->name('loops.restoreAll');
                Route::delete('/loops', 'LoopController@destroyAll')->name('loops.destroyAll');
                Route::get('/loops/grid', 'LoopController@grid')->name('loops.grid');
                Route::get('/loops/loop_user_details/{id}', 'LoopController@loopDetails')->name('loops.loop_user_details');
                // Route::resource('/loops', 'LoopController', ['as'=> 'admin_loops']);
                Route::resource('/loops', 'LoopController');

                // USER ROUTES
                Route::put('/users/restore/{id}', 'UserController@restore')->name('users.restore');
                Route::put('/users/restore', 'UserController@restoreAll')->name('users.restoreAll');
                Route::delete('/users', 'UserController@destroyAll')->name('users.destroyAll');
                Route::get('/users/grid', 'UserController@grid')->name('users.grid');
                Route::resource('/users', 'UserController');

                // SETTING ROUTES
                //Route::get('/settings', 'DashboardController@index')->name('admin_settings');
                Route::get('/settings', 'SettingController@index')->name('settings.index');
                Route::post('/settings', 'SettingController@store')->name('settings.store');


			});  // End Role Routes


			Route::resource('/languages', 'LanguageController');
			// Route::post('/languages/{id}', 'LanguageController@update')->name('languages');

		}); // End Authenticated Admin routes
	}); // End Admin Routes

    Route::group(['namespace' => 'Web','middleware' => [ 'WebsiteVisitorCount'] ], function () {

        Route::get('/pages', 'PageController@index')->name('pages');
        Route::get('/pages/{page}/{slug?}', 'PageController@details')->name('page_details');
        /**
         * User Routes
         */
        Route::group([ 'prefix'=> 'user'], function () {

            // USER LOGIN ROUTES
            Route::group([ 'middleware' => ['guest']], function () {
                Route::get('/login', 'UserController@login');
                Route::post('/login', 'UserController@doLogin')->name('user.login');
                Route::get('/register', 'UserController@register');
                Route::post('/register', 'UserController@doRegister')->name('user.register');
                Route::get('/verification-code/{phone}', 'UserController@verification')->name('users.verification');

                // USER RESET PASSWORD ROUTES
                Route::get('/forget-password', 'UserController@forgetPasswordForm')->name('user.forgetPasswordForm');
                Route::post('/forget-password-code', 'UserController@generateForgetPasswordCode')->name('user.generateForgetPasswordCode');
                Route::get('/type-verification-code', 'UserController@typeVerificationCodeForm')->name('user.typeVerificationCodeForm');
                Route::post('/verify-code', 'UserController@verifyCode')->name('user.verifyCode');
                Route::get('/new-password-form', 'UserController@newPasswordForm')->name('user.newPasswordForm');
                Route::post('/new-password', 'UserController@typeNewPassword')->name('user.typeNewPassword');
                Route::get('/getLocationInfo', 'UserController@getLocationInfo')->name('user.getLocationInfo');

            });

            // VERIFICATION ROUTES
            Route::post('/resend-code', 'UserController@resendCode')->name('user.resendCode');
            Route::post('/verification', 'VerificationController@verifyCode')->name('verification.verifyCode');

            Route::group([ 'middleware' => ['user_auth']], function () {
                // USER LOG OUT ROUTE
                Route::any('/logout', 'UserController@logout')->name('user.logout');

                Route::get('/profile', 'UserController@profile')->name('user.profile');
                Route::get('/edit-profile', 'UserController@editProfile')->name('user.editProfile');
                Route::post('/edit-profile', 'UserController@updateProfile')->name('user.updateProfile');

                // Wallet ROUTES
                Route::group([ 'prefix'=> 'wallet' ], function () {
                    Route::get('/{type?}', 'UserWalletController@index')->name('userswallet.index');
                    Route::get('/pay/{type?}', 'UserWalletController@pay')->name('userswallet.pay');
                }); //End Wallet Routes

                // LOOP ROUTES
                Route::group([ 'prefix'=> 'loops' ], function () {
                    Route::get('/', 'LoopController@index')->name('loops.index');
                    Route::get('/available', 'LoopController@available')->name('loops.available');
                    Route::get('/chekmonths', 'LoopController@chekMonths')->name('loops.chekMonths');
                    Route::post('/subscribe', 'LoopController@subscribe')->name('loops.subscribe');
                    Route::get('/payshare/{loop_id}', 'LoopController@payShare')->name('loops.payshare');
                    Route::get('/details/{loop_id?}', 'LoopController@loopDetails')->name('loops.details');
                    Route::get('/cancel/{loop_id}', 'LoopChangeController@cancel')->name('loops.cancel');
                    Route::get('/verify/{type}/{loop_id}', 'LoopController@verify')->name('loops.verify');
                }); // End Loops routes

            }); // End Authenticated user routes
        }); // End user Routes
    }); // End Web Routes

});
