<?php

namespace App\Http\Middleware;

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

class NoIndexPrivatePages
{
    public function handle(Request $request, Closure $next): Response
    {
        $response = $next($request);

        $publicRoutes = [
            'landing.home',
            'landing.about',
            'landing.contact',
            'landing.privacy',
            'sitemap.xml',
            'robots.txt',
        ];

        if (! $request->routeIs($publicRoutes)) {
            $response->headers->set('X-Robots-Tag', 'noindex, nofollow, noarchive, nosnippet');
        }

        return $response;
    }
}