<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureMeetupAdmin
{
    public function handle(Request $request, Closure $next): Response
    {
        $eventId = $request->session()->get('meetup_admin_event');

        if (! $eventId || ! $request->session()->get('meetup_admin_authenticated')) {
            return redirect()->route('mexco.admin.login')
                ->with('error', 'Please sign in to the organiser dashboard.');
        }

        return $next($request);
    }
}
