<?php

//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 within a group which
| contains the "web" middleware group. Now create something great!
|
*/

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

Route::get('language/{id}/{slug?}', 'LanguageController@details');
/**
 * Localization Group
 */

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

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

        Route::get('/', 'HomeController@index')->name('home');

        Route::group(['namespace' => 'Web'], function () {
            Route::get('/login/', 'UserController@login')->name('user.login');
            Route::post('/login', 'UserController@doLogin')->name('user.doLogin');
            Route::get('/register', 'UserController@register')->name('user.register');
            Route::post('/register', 'UserController@doRegister')->name('user.doRegister');
            Route::any('/logout', 'UserController@logout')->name('user.logout');
            Route::get('/contact-us', 'ContactController@index')->name('contactUs.index');
            Route::post('/contact-us', 'ContactController@store')->name('contactUs.store');
            Route::get('/user-newsletters', 'UserController@newsletters')->name('user.newsletters');
            Route::get('/newsletters', 'UserController@newsletters')->name('user.newsletters');
            Route::get('our-categories/{category?}', 'CategoryController@show')->name('our-categories.show');
            Route::get('our-courses/{course}', 'CategoryController@courses')->name('our-courses.courses');
            Route::get('/coursesSearch', 'CategoryController@coursesSearch')->name('coursesSearch');


            // Guid and other pages
            Route::get('pages/{page_name}', 'PagesController@index')->name('ourPages.index');
            Route::get('our-faqs', 'FaqController@index')->name('ourFaqs.index');
            Route::get('our-news', 'NewsController@index')->name('ourNews.index');
            Route::get('our-news/{article}/{category}', 'NewsController@show')->name('ourNews.show');
            Route::get('/about-us', 'AboutController@index')->name('aboutUs.index');


            Route::get('/forgetPassword', 'UserController@forgetPassword')->name('user.forgetPassword');
            Route::post('/generateToken', 'UserController@generateToken')->name('user.generateToken');
            Route::get('/verificationCodeForm', 'UserController@verificationCodeForm')->name('user.verificationCodeForm');
            Route::post('/verifyCodeWasSendToEmail', 'UserController@verifyCodeWasSendToEmail')->name('user.verifyCodeWasSendToEmail');
            Route::get('/newPasswordForm', 'UserController@newPasswordForm')->name('user.newPasswordForm');
            Route::post('/resetPassword', 'UserController@resetPassword')->name('user.resetPassword');
            Route::get('/verification/{token}', 'UserController@verification')->name('user.verification');


            Route::group(['middleware' => 'userAuth'], function (){
                Route::get('/profile', 'UserController@index')->name('user.profile');
                Route::put('/profile/{user}', 'UserController@update')->name('user.update');
                Route::post('/updatePaymentInfo', 'UserController@updatePaymentInfo')->name('user.updatePaymentInfo');

                Route::get('courseSubscription/{course}', 'CategoryController@courseSubscription')->name('courseSubscription');
                Route::get('subscription/{course}', 'CategoryController@subscription')->name('subscription');
                Route::post('doSubscription', 'CategoryController@doSubscription')->name('doSubscription');

            });

        });

    });



    /**
     * this route for the central admin and central super admin to enable them to use this website
     */
    Route::get('/login/{admin_token}', 'Auth\LoginController@super_admin_login')->name('super_admin_login');

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

//	Route::get('/home', 'HomeController@index')->name('home');
    /**
     * 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' => 'adminAuth'], function () {
            Route::get('/', 'DashboardController@index')->name('dashboard');

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

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

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

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

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

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

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

                // LESSON ROUTES
                Route::put('/lessons/restore/{id}', 'LessonController@restore')->name('lessons.restore');
                Route::put('/lessons/restore', 'LessonController@restoreAll')->name('lessons.restoreAll');
                Route::delete('/lessons', 'LessonController@destroyAll')->name('lessons.destroyAll');
                Route::get('/lessons/grid', 'LessonController@grid')->name('lessons.grid');
                Route::get('/getCourseUnit', 'LessonController@getCourseUnit')->name('lessons.getCourseUnit');
                Route::resource('/lessons', 'LessonController');

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

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


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

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

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

                Route::put('/subscriptions/restore/{id}', 'SubscriptionController@restore')->name('subscriptions.restore');
                Route::put('/subscriptions/restore', 'SubscriptionController@restoreAll')->name('subscriptions.restoreAll');
                Route::delete('/subscriptions', 'SubscriptionController@destroyAll')->name('subscriptions.destroyAll');
                Route::get('/subscriptions/grid', 'SubscriptionController@grid')->name('subscriptions.grid');
                Route::get('/subscriptions', 'SubscriptionController@index')->name('subscriptions.index');
                Route::resource('/subscriptions', 'SubscriptionController');

                // NEWSLETTER ROUTES
                Route::put('/newsletters/restore/{id}', 'NewsletterController@restore')->name('newsletters.restore');
                Route::put('/newsletters/restore', 'NewsletterController@restoreAll')->name('newsletters.restoreAll');
                Route::delete('/newsletters', 'NewsletterController@destroyAll')->name('newsletters.destroyAll');
                Route::get('/newsletters/grid', 'NewsletterController@grid')->name('newsletters.grid');
                Route::get('/newsletters/mailsList', 'NewsletterController@mailsList')->name('newsletters.mailsList');
                Route::get('/newsletters/mailsListGrid', 'NewsletterController@mailsListGrid')->name('newsletters.mailsListGrid');
                Route::get('/newsletters/mailsListMore/{id}', 'NewsletterController@mailsListMore')->name('newsletters.mailsListMore');
                Route::resource('/newsletters', 'NewsletterController');

                // VISITOR MESSAGE ROUTES
                Route::put('/visitorMessages/restore/{id}', 'VisitorMessageController@restore')->name('visitorMessages.restore');
                Route::put('/visitorMessages/restore', 'VisitorMessageController@restoreAll')->name('visitorMessages.restoreAll');
                Route::delete('/visitorMessages', 'VisitorMessageController@destroyAll')->name('visitorMessages.destroyAll');
                Route::get('/visitorMessages/grid', 'VisitorMessageController@grid')->name('visitorMessages.grid');
                Route::resource('/visitorMessages', 'VisitorMessageController');

                // 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');
                Route::post('/modules-settings', 'SettingController@modules')->name('settings.modules');


            });  // End Role Routes

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

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

});
