<?php

/*
|--------------------------------------------------------------------------
| 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!
|
*/


Auth::routes();

Route::get('/logout', function(){
    Auth::logout();
    return Redirect::to('login');
})->name('logout');

/*
Route::get('locale/{locale}', function ($locale) {
    \Session::put('locale', $locale);
    if(Auth::check()){
        $user = Auth::user();
        $user->lang = $locale;
        $user->save();
    }
    return redirect()->back();
})->name('locale');
*/

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

/*Route::post('/register/data', 'HomeController@register')->name('register_data');
Route::post('/user/check/mail', 'HomeController@checkMail')->name('user_check_mail');

Route::get('/register/verify/{confirmationCode}', 'HomeController@verify')->name('register_verify');

Route::get('/status/register', 'HomeController@statusRegister')->name('status_register');
Route::get('/status/verify', 'HomeController@statusVerify')->name('status_verify');
Route::get('/status/error', 'HomeController@statusError')->name('status_error');


Route::get('/user/update_email_confirm/{token}', 'UpdateEmailController@activateMail')->name('user_update_email_confirm');
*/

Route::get('/data_protected', 'HomeController@legalDataProtected')->name('data_protected');
Route::get('/imprint', 'HomeController@legalImprint')->name('imprint');

Route::post('/loading/modal', 'HomeController@loadingModal')->name('loading_modal');


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

Route::get('/check/login/{identify}/{token}/{show?}', 'HomeController@checkLogin')->name('check_login');

Route::get('/user/update_email_confirm/{token}', 'UserUpdateEmailController@activateMail')->name('user_update_email_confirm');


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

    Route::get('storage/{type?}/{file?}', function($type = null, $file = null)
    {
        if($type == 'xls'){
            $path = storage_path("app/export/");
            $filename = $file.'.xls';
        }

        if (file_exists($path.$filename)) {
            return Response::download($path.$filename, $filename);
        }
    })->name('storage');

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


   /* Route::get('/user/edit', 'UserController@userEdit')->name('user_edit');

   */
    Route::get('/user/edit', 'UserDataController@userEdit')->name('user_edit');
    Route::post('/user/edit', 'UserDataController@userEditStore')->name('user_edit');


    Route::get('/user/update_password', 'UserUpdatePasswordController@updatePassword')->name('user_update_password');
    Route::post('/user/update_password', 'UserUpdatePasswordController@updatePasswordStore')->name('user_update_password');

    Route::get('/user/update_password_first', 'UserUpdatePasswordController@updatePasswordFirst')->name('user_update_password_first');
    Route::post('/user/update_password_first', 'UserUpdatePasswordController@updatePasswordFirstStore')->name('user_update_password_first');

    Route::get('/user/update_email', 'UserUpdateEmailController@index')->name('user_update_email');
    Route::post('/user/update_email', 'UserUpdateEmailController@update')->name('user_update_email');

    Route::get('/user/delete_account', 'UserDeleteController@deleteAccount')->name('user_delete_account');
    Route::post('/user/delete_account', 'UserDeleteController@deleteAccountAction')->name('user_delete_account');

    Route::post('/user/data/accepted/form', 'UserDataController@userDataAcceptedForm')->name('user_data_accepted_form');





});

Route::group(['middleware' => ['admin']], function()
{
    //drafts
    Route::get('/drafts/{step?}', 'DraftController@index')->name('drafts');

    Route::get('/draft/detail/{id}', 'DraftController@detail')->name('draft_detail');
    Route::post('/draft/detail/{id}', 'DraftController@store')->name('draft_detail');

    Route::get('/draft/item/delete/{id}', 'DraftController@itemDelete')->name('draft_item_delete');
    Route::get('/draft/delete/{id}', 'DraftController@delete')->name('draft_delete');

    Route::post('/draft/type/update', 'DraftController@typeUpdate')->name('draft_type_update');
    Route::get('/draft/type/delete/{id}', 'DraftController@typeDelete')->name('draft_type_delete');

    Route::get('/draft/load/new', 'DraftController@loadNew')->name('draft_load_new');
    Route::post('/draft/load/new', 'DraftController@loadNewAction')->name('draft_load_new');

    Route::get('/draft/load/old', 'DraftController@loadOld')->name('draft_load_old');
    Route::post('/draft/load/old', 'DraftController@loadOldAction')->name('draft_load_old');

    //travel Programs
    Route::get('/travel/programs/{step?}', 'TravelProgramController@index')->name('travel_programs');

    Route::get('/travel/program/detail/{id}', 'TravelProgramController@detail')->name('travel_program_detail');
    Route::post('/travel/program/detail/{id}', 'TravelProgramController@store')->name('travel_program_detail');

    Route::post('/travel/program/class/update', 'TravelProgramController@classUpdate')->name('travel_program_class_update');
    Route::get('/travel/program/class/delete/{id}', 'TravelProgramController@classDelete')->name('travel_program_class_delete');

    Route::post('/travel/program/draft/update', 'TravelProgramController@draftUpdate')->name('travel_program_draft_update');
    Route::get('/travel/program/draft/delete/{id}', 'TravelProgramController@draftDelete')->name('travel_program_draft_delete');

    //bookings
    Route::get('data/table/bookings', 'DataTableController@getBookings')->name('data_table_bookings');
    Route::get('/bookings/{step?}', 'BookingController@index')->name('bookings');
    Route::get('/booking/detail/{id}', 'BookingController@detail')->name('booking_detail');
    Route::post('/booking/detail/{id}', 'BookingController@store')->name('booking_detail');

    Route::get('/booking/draft_item/delete/{id}', 'BookingController@draftItemDelete')->name('booking_draft_item_delete');


    Route::get('/requests/{step?}', 'RequestController@index')->name('requests');
    Route::get('/lead/detail/{id}', 'LeadController@detail')->name('lead_detail');

    Route::get('data/table/requests', 'DataTableController@getRequests')->name('data_table_requests');


    //CMS

    //feedback
    Route::get('/cms/feedback', 'CMS\CMSFeedbackController@index')->name('cms_feedback');
    Route::get('/cms/feedback/detail/{id}', 'CMS\CMSFeedbackController@detail')->name('cms_feedback_detail');
    Route::post('/cms/feedback/detail/{id}', 'CMS\CMSFeedbackController@store')->name('cms_feedback_detail');
    Route::get('/cms/feedback/delete/{id}', 'CMS\CMSFeedbackController@delete')->name('cms_feedback_delete');


    Route::get('/cms/travel_magazine', 'CMS\CMSTravelMagazineController@index')->name('cms_travel_magazine');
    Route::get('/cms/travel_magazine/detail/{id}', 'CMS\CMSTravelMagazineController@detail')->name('cms_travel_magazine_detail');
    Route::post('/cms/travel_magazine/detail/{id}', 'CMS\CMSTravelMagazineController@store')->name('cms_travel_magazine_detail');
    Route::get('/cms/travel_magazine/delete/{id}', 'CMS\CMSTravelMagazineController@delete')->name('cms_travel_magazine_delete');


    Route::get('/cms/sidebar', 'CMS\CMSSidebarController@index')->name('cms_sidebar');
    Route::get('/cms/sidebar/detail/{id}', 'CMS\CMSSidebarController@detail')->name('cms_sidebar_detail');
    Route::post('/cms/sidebar/detail/{id}', 'CMS\CMSSidebarController@store')->name('cms_sidebar_detail');
    Route::get('/cms/sidebar/delete/{id}', 'CMS\CMSSidebarController@delete')->name('cms_sidebar_delete');

    Route::get('/cms/content', 'CMS\CMSContentController@index')->name('cms_content');
    Route::post('/cms/content/store', 'CMS\CMSContentController@store')->name('cms_content_store');
    Route::post('/cms/content/load/modal', 'CMS\CMSContentController@loadModal')->name('cms_content_load_modal');
    Route::get('/cms/content/delete/{id}', 'CMS\CMSContentController@delete')->name('cms_content_delete');


});

//login pages for worker
Route::group(['middleware' => ['superadmin']], function() {
    //leads
    Route::get('/admin/users', 'AdminUserController@index')->name('admin_users');
    Route::get('/admin/user/edit/{user_id}', 'AdminUserController@edit')->name('admin_user_edit');
    Route::post('/admin/user/store', 'AdminUserController@store')->name('admin_user_store');
    Route::get('/admin/user/delete/{user_id}', 'AdminUserController@deleteUser')->name('admin_user_delete');

    Route::get('data_table', 'DataTableController@datatable')->name('data_table');
   // Route::get('datatables/leads', 'DataTableController@getLeads')->name('datatables-leads');
    Route::get('data/table/users', 'DataTableController@getUsers')->name('data_table_users');


    Route::get('/admin/translate/all', 'TranslationController@index')->name('admin_translate_all');
    Route::get('/admin/translate/all/edit/{lang}/{from?}', 'TranslationController@edit')->name('admin_translate_all_edit');
    Route::post('/admin/translate/all/update/{lang}/{from?}', 'TranslationController@update')->name('admin_translate_all_update');

    Route::get('/admin/translate/file', 'TranslationFileController@index')->name('admin_translate_file');
    Route::get('/admin/translation/file/{file}/{language?}/{langsource?}/{show?}', 'TranslationFileController@edit')->name('admin_translate_file_edit');
    Route::post('/admin/translation/file/{file}/{language?}/{langsource?}/{show?}', 'TranslationFileController@update')->name('admin_translate_file_update');


    Route::get('/admin/settings/travel/country', 'Settings\TravelCountryController@index')->name('admin_settings_travel_country');
    Route::get('/admin/settings/travel/country/detail/{id}', 'Settings\TravelCountryController@detail')->name('admin_settings_travel_country_detail');
    Route::post('/admin/settings/travel/country/detail/{id}', 'Settings\TravelCountryController@store')->name('admin_settings_travel_country_detail');
    Route::get('/admin/settings/travel/country/delete/{id}', 'Settings\TravelCountryController@delete')->name('admin_settings_travel_country_delete');


    Route::get('/admin/settings/travel/nationality', 'Settings\TravelNationalityController@index')->name('admin_settings_travel_nationality');
    Route::post('/admin/settings/travel/nationality/update', 'Settings\TravelNationalityController@update')->name('admin_settings_travel_nationality_update');
    Route::get('/admin/settings/travel/nationality/delete/{id}', 'Settings\TravelNationalityController@delete')->name('admin_settings_travel_nationality_delete');


    Route::get('/admin/settings/travel/program/{id?}', 'Settings\TravelAgendaController@index')->name('admin_settings_travel_program');
    Route::post('/admin/settings/travel/program/update', 'Settings\TravelAgendaController@update')->name('admin_settings_travel_program_update');
    Route::get('/admin/settings/travel/program/delete/{id}', 'Settings\TravelAgendaController@delete')->name('admin_settings_travel_program_delete');


});


/*
use App\Mail\MailResetPassword;

Route::get('/send_test_email', function(){

        try {
            Mail::to('kevin.adametz@me.com')->send(new MailResetPassword('asdasd', Auth::user()));

       Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message) {
              $message->to('kevin.adametz@me.com', 'Kevin Adametz');
              $message->subject('testing Networktrips');
          });



		} catch (\Exception $e) {
		    dd($e->getMessage());
		}

		$fail = Mail::failures();

		if(!empty($fail)) throw new \Exception('Could not send message to '.$fail[0]);

	});
*/
