<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\MoodController;
use App\Http\Controllers\ExerciseController;
use App\Http\Controllers\AIChatController;
use App\Http\Controllers\PageController;
use Illuminate\Support\Facades\Route;

Route::get('/', [PageController::class, 'home'])->name('home');
Route::get('/about', [PageController::class, 'about'])->name('about');
Route::get('/contact', [PageController::class, 'contact'])->name('contact');
Route::get('/privacy', [PageController::class, 'privacy'])->name('privacy');
Route::get('/terms', [PageController::class, 'terms'])->name('terms');
Route::get('/disclaimer', [PageController::class, 'disclaimer'])->name('disclaimer');
Route::get('/sitemap.xml', [PageController::class, 'sitemap'])->name('sitemap');

Route::post('/dark-mode/toggle', function (Illuminate\Http\Request $request) {
    $darkMode = $request->cookie('dark_mode') === 'true' ? 'false' : 'true';
    return redirect()->back()->withCookie(cookie('dark_mode', $darkMode, 60*24*365));
})->name('dark-mode.toggle');

Route::post('/rtl/toggle', function (Illuminate\Http\Request $request) {
    $rtl = $request->cookie('rtl') === 'true' ? 'false' : 'true';
    return redirect()->back()->withCookie(cookie('rtl', $rtl, 60*24*365));
})->name('rtl.toggle');

Route::middleware('auth')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::resource('moods', MoodController::class)->except(['edit', 'update']);
    Route::get('/exercises', [ExerciseController::class, 'index'])->name('exercises.index');
    Route::get('/exercises/{exercise}', [ExerciseController::class, 'show'])->name('exercises.show');
    Route::get('/ai/chat', [AIChatController::class, 'index'])->name('ai.chat');
    Route::post('/ai/chat', [AIChatController::class, 'send'])->name('ai.send');
    Route::get('/ai/history', [AIChatController::class, 'history'])->name('ai.history');
    Route::get('/ai/conversation/{conversation}', [AIChatController::class, 'show'])->name('ai.conversation');
    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');
});

require __DIR__.'/auth.php';
