<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\UserController;
use App\Http\Controllers\ClientController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\LogoutController;
use App\Http\Controllers\CreateUserController;
use Illuminate\Support\Facades\Auth;


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

    Route::controller(ClientController::class)->group(function () {
        Route::get('/dashboard', 'dashboard')->name('dashboard');
        Route::post('/create-users', 'createUsers')->name('users.create')->middleware('authorization');
    });

    Route::controller(LogoutController::class)->group(function () {
        Route::post('/logout', [LogoutController::class, 'logout'])->name('logout');
    });
});

Route::controller(LoginController::class)->group(function () {

    Route::get('/login', function () {
        if (Auth::check()) {
            return redirect('dashboard', 302);
        }
        return view('login');
    })->name('login');

    Route::get('/', function () {
        if (Auth::check()) {
            return redirect('dashboard', 302);
        }
        return view('login');
    });

    Route::post('/login',  [LoginController::class, 'login'])->name('login-post');
});
