<?php

use Illuminate\Support\Facades\App;
use App\Http\Livewire\CartComponent;
use App\Http\Livewire\HomeComponent;
use App\Http\Livewire\ShopComponent;
use Illuminate\Support\Facades\Route;
use App\Http\Livewire\DetailsComponent;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Session;
use App\Http\Controllers\UserController;
use App\Http\Livewire\CheckoutComponent;
use App\Http\Livewire\User\UserDashboardComponent;
use App\Http\Livewire\Admin\AdminDashboardComponent;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

/*
Route::get('/', function () {
    return view('welcome');
});
*/

Route::get('/', HomeComponent::class)->name('home.index');
Route::post('/tour-daily', [HomeComponent::class, 'processForm'])->name('home.process');
Route::get('/get-destinations/{originId?}', [HomeComponent::class, 'getDestinations'])->name('home.destination');
Route::get('/get-total', [HomeComponent::class, 'getTotal'])->name('home.total');
Route::get('/load-form', [HomeComponent::class, 'loadForm'])->name('home.loadForm');




Route::get('/shop', ShopComponent::class)->name('shop');

Route::get('/product/{slug}', DetailsComponent::class)->name('product.details');

Route::get('/cart', CartComponent::class)->name('shop.cart');

Route::get('/checkout', CheckoutComponent::class)->name('shop.checkout');

/*
Route::get('/user', UserComponent::class)->name('user');
Route::post('/users.store', UserComponent::class)->name('users.store');
/
*/

Route::get('/user', [UserController::class, 'index'])->name('user.index');
Route::post('/user.store', [UserController::class, 'store'])->name('user.store');


/*
Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
*/

Route::middleware('auth')->group(function () {
    //Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    //Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    //Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
    Route::get('/clear-cache', function() {
		$text = "Start...";
		Artisan::call('cache:clear');
		$text = $text . Artisan::output().'<br>';
		Artisan::call('route:clear');
		$text = $text . Artisan::output().'<br>';
		Artisan::call('config:clear');
		$text = $text . Artisan::output().'<br>';
		Artisan::call('view:clear');
		$text = $text . Artisan::output().'<br>';
		return $text;
    });
});


Route::middleware(['auth'])->group(function(){
    Route::get('/user/dashboard', UserDashboardComponent::class)->name('user.dashboard');
});

Route::middleware(['auth', 'authadmin'])->group(function(){
    Route::get('/admin/dashboard', AdminDashboardComponent::class)->name('admin.dashboard');
 
});

Route::get('setlocale/{locale}', function ($language) {        
    if(array_key_exists($language, config('languages'))){            
        session()->put('applocale', $language);        
     }        
     return back();     
    //Session::put('locale', $locale);
    //return redirect()->back();
})->name('setlocale');

require __DIR__.'/auth.php';
