<?php

namespace App\Http\Controllers\Dashboard;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
{
    public function index(Request $request)
    {
        $user = Auth::user();
        if (!$user) {
            return redirect()->route('login');
        }

        $collapsed = session()->get('collapsed', false);
        $pageRoutes = [
            ['path' => '/my-profile', 'name' => 'Home'],
            ['path' => '/my-profile/users', 'name' => 'Users', 'params' => true],
        ];
        $root = $request->path() === '/my-profile';

        return view('dashboard.layout', compact('collapsed', 'user', 'pageRoutes', 'root'));
    }

    public function logout(Request $request)
    {
        Auth::logout();
        return redirect()->route('login')->with('success', 'Logged out due to inactivity');
    }
}