<?php

namespace App\Http\Middleware;

use App\Support\RegistrationSettings;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureRegistrationEnabled
{
    public function handle(Request $request, Closure $next): Response
    {
        if (! RegistrationSettings::isEnabled()) {
            return redirect()
                ->route('login')
                ->with('error', 'Registration is currently disabled. Please contact an administrator.');
        }

        return $next($request);
    }
}
