<?php

use Illuminate\Support\Facades\Route;
use App\Post;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
use Spatie\Sitemap\SitemapGenerator;

Route::get('/clear', function() {
    Artisan::call('cache:clear');
    Artisan::call('config:clear');
    Artisan::call('config:cache');
    Artisan::call('view:clear');
    return "Cache is cleared";
});
Route::get('/storage-link', function() {
    Artisan::call('storage:link');
    return "Storage is Linked";
});
//multi langages

Route::get('/locale/{lang}','HomeController@lange'); 


// Route::get('/test', function() {
//     App::setLocale('fr');

//     if( App::setLocale('fr') ) {
//         dd(App::getLocale());
//     }

// });


Auth::routes(['register' => false]);
Auth::routes([
    'register' => false, // Registration Routes...
    'reset' => false, // Password Reset Routes...
    'verify' => false, // Email Verification Routes...
  ]);


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

    
    Route::get('/offres-mutuelle-sante', function () {
        return view('front.offers.index');
    });
    Route::get('/tpe-pme', function () {
        return view('front.offers.tpe');
    });
    Route::get('/grands-comptes', function () {
        return view('front.offers.grands');
    });
    Route::get('/independants', function () {
        return view('front.offers.independants');
    });
    
    
    
    
    Route::get('/comment-ca-marche', function () {
        return view('front.how-it-works');
    });
    
    Route::get('/pegahealth-assurance', function () {
        return view('front.pegahealth');
    });
    
    Route::get('/maladie-complementaire', function () {
        return view('front.complementary-disease');
    });
    
    
    Route::get('/assurance-sante', function () {
        return view('front.health_insurance.index');
    });
    Route::get('/rh', function () {
        return view('front.health_insurance.rh');
    });
    Route::get('/directeur', function () {
        return view('front.health_insurance.directeur');
    });
    
    
    
    Route::get('/contactez-nous', function () {
        return view('front.contact.index');
    });
    
    Route::get('/contact-tpe-pme', function () {
        return view('front.contact.tpe');
    });
    
    Route::get('/contact-grands-comptes', function () {
        return view('front.contact.grands');
    });
    
    Route::get('/contact-independants', function () {
        return view('front.contact.independants');
    });
    
    
    Route::get('/mentions-legales-generales', function () {
        return view('front.tos');
    });
    
    Route::get('/sous-traitance', function () {
        return view('front.sub-contracting');
    });
    
    
    
    Route::post('/subscribe', 'HomeController@subscribe')->name('subscribe');
    
  
 
    Route::get('/blog','Front\BlogController@blog')->name('blog');
    Route::get('/category/{slug}','Front\BlogController@postByCategory')->name('postByCategory');
    Route::get('/tag/{slug}','Front\BlogController@tagBlog')->name('TagBlog');
    Route::get('/search','Front\BlogController@search')->name('search');
    Route::get('/blog/{blog_id}/{slug}','Front\BlogController@showBlog')->name('showBlog');
    Route::get('/blog/NextPost/{blog_id}/{slug}', 'Front\BlogController@NextPost')->name('NextPost');
    Route::get('/blog/PrevPost/{blog_id}/{slug}', 'Front\BlogController@PrevPost')->name('PrevPost');

    Route::post('/Chate_admin2', 'HomeController@Chate_admin2')->name('Chate_admin2');
    Route::post('/contactMessage', 'HomeController@contactMail')->name('contactMessage');
    Route::post('/subscribe', 'HomeController@subscribe')->name('subscribe');



    Route::get('genrate-sitemap', function(){
        $sitemap = App::make("sitemap");
        $sitemap->add(URL::to(''), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('our-services'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('digital-transformation-consulting'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('uxui-design'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('web-and-mobile-development'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('software-development'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('innovation'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('contact'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('terms-and-condition'), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
        $sitemap->add(URL::to('blog'), '2012-08-26T12:30:00+02:00', '0.9', 'monthly');
        $posts = Post::All();
        foreach ($posts as $post)
        {
            $sitemap->add(URL::to('blog/'.$post->id.'/'.$post->slug), $post->updated_at,'1.0', 'daily');
        }
        $sitemap->store('xml', 'sitemap');
        return redirect(url('sitemap.xml'));
    });














/////////////////////////////////////////////////////////////////////////////////////////////////////
//auth admin
//les Routes de L'authentification Admin
Route::group(['prefix'=>'admin','namespace'=>'Auth','as'=>'admin.'],function(){
    Route::get('/login','adminController@showLoginForm')->name('login');
    Route::post('/login','adminController@login')->name('login');
    Route::post('/logout','adminController@logout')->name('logout'); 
});


//admin
Route::group(['prefix'=>'admin','namespace'=>'Admin','middleware'=>['auth:admin','admin'],'as'=>'admin.'], function(){ 
       Route::get('/','DashboardController@index');
       Route::get('dashboard','DashboardController@index')->name('dashboard');
       Route::get('chartmonth', 'DashboardController@chartmonth')->name('chartmonth');

    
       Route::resource('/setting','DashboardController');

       Route::resource('banner','BannerController');
       Route::get('banner/enable/{id}','BannerController@enable'); 
       Route::resource('partners','PartnerController');

       //POSTs
       Route::resource('tag','Blog\TagController');
       Route::resource('categoriePost','Blog\CategoryController');
       Route::resource('post','Blog\PostController');
       Route::get('pending/post', 'Blog\PostController@pending')->name('post.pending');
       Route::get('/post/{id}/approve', 'Blog\PostController@approval')->name('post.approve');
       Route::get('post/enable/{id}','Blog\PostController@enable'); 


      //galleries
      Route::resource('galerie','WebSetting\GalerieController');
      Route::POST('galerie/deletePhoto','WebSetting\GalerieController@deletePhoto')->name('deletePhotoGalerie');
      Route::get('galerie/enable/{id}','WebSetting\GalerieController@enable');  

      //comptes admins et agents
      Route::resource('comptes','AdminController');
      Route::get('compte/enable/{id}','AdminController@enable');  
      Route::get('profile','AdminController@profile')->name('profile');
      Route::post('profile','AdminController@profileUpdate')->name('profile.update');   
      Route::post('changepassword','AdminController@changePasswordUpdate')->name('changepassword.update');
 

       /*---------settings----------*/
       Route::get('settings', 'DashboardController@settings')->name('settings');
       Route::post('settings', 'DashboardController@settingStore')->name('settings.store');
       /*--------message-----------*/
       Route::get('subscribe','DashboardController@subscribe')->name('subscribe');
       Route::delete('subscribe/delete/{id}','DashboardController@subscribeDelete')->name('subscribes.destroy');
       
       Route::get('message','DashboardController@message')->name('message');
       Route::get('message/read/{id}','DashboardController@messageRead')->name('message.read');
       Route::get('message/replay/{id}','DashboardController@messageReplay')->name('message.replay');
       Route::post('message/replay','DashboardController@messageSend')->name('message.send');
       Route::post('message/readunread','DashboardController@messageReadUnread')->name('message.readunread');
       Route::delete('message/delete/{id}','DashboardController@messageDelete')->name('messages.destroy');
       Route::post('message/mail', 'DashboardController@contactMail')->name('message.mail');
 


   });



