<?php

namespace App\Http\Controllers\Dashboard;

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

class HeaderController extends Controller
{
    public function index(Request $request)
    {
        $user = Auth::user();
        if (!$user) {
            return redirect()->route('login');
        }
        $collapsed = session()->get('collapsed', false); // Simulate toggle state
        return view('dashboard.header', compact('user', 'collapsed'));
    }

    public function toggle(Request $request)
    {
        $collapsed = !$request->input('collapsed', false);
        session()->put('collapsed', $collapsed);
        return response()->json(['collapsed' => $collapsed]);
    }

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