<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class DarkMode
{
    public function handle(Request $request, Closure $next)
    {
        $darkMode = $request->cookie('dark_mode') === 'true' ||
            ($request->user() && $request->user()->dark_mode);

        view()->share('darkMode', $darkMode);

        return $next($request);
    }
}
