<?php

use App\Http\Controllers\LoginController;
use App\Http\Controllers\ProfileController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
})->name('home');

Route::get('/form-csrf', function () {
    return view('form-csrf');
});

Route::get('/debug-https', function (Request $request) {
    return response()->json([
        'isSecure' => $request->isSecure(),
        'url' => $request->url(),
        'scheme' => $request->getScheme(),
        'headers' => [
            'X-Forwarded-Proto' => $request->header('X-Forwarded-Proto'),
            'X-Forwarded-For' => $request->header('X-Forwarded-For'),
            'X-Forwarded-Host' => $request->header('X-Forwarded-Host'),
            'X-Forwarded-Port' => $request->header('X-Forwarded-Port'),
            'CF-Visitor' => $request->header('CF-Visitor'),
        ],
        'SERVER_HTTPS' => $_SERVER['HTTPS'] ?? 'not set',
        'REQUEST_SCHEME' => $_SERVER['REQUEST_SCHEME'] ?? 'not set',
    ]);
});

Route::get('/resources', function () {
    return view('resources');
})->name('resources.index');

// Routes d'authentification
Route::get('/login', [LoginController::class, 'login'])->name('login');
Route::post('/login', [LoginController::class, 'store'])->name('login.store');

Route::get('/register', [LoginController::class, 'register'])->name('register');
Route::post('/register', [LoginController::class, 'storeRegister'])->name('register.store');

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

// Routes protégées (authentifiées)
Route::middleware('auth')->group(function () {
    Route::get('/profile/settings', [ProfileController::class, 'settings'])->name('profile.settings');
    Route::put('/profile/update', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
