import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  const token = request.cookies.get("token")?.value;
  const pathname = request.nextUrl.pathname;

  if (pathname === "/" && token) {
    return NextResponse.redirect(new URL("/Impresiones", request.url));
  }

  if (!token && pathname != "/") {
    console.log("No hay token, redirigiendo a login");
    return NextResponse.redirect(new URL("/", request.url));
  }

  return NextResponse.next();
}

export const config = {
  matcher: [   
    "/", 
    "/Reportes",
    "/Monitor",
    "/QuitarSancion",
    "/Programas",
    "/Mensajes",
    "/Inscritos",
    "/Inscripciones",
    "/InformacionEquipo",
    "/Impresiones",
    "/CambiarPass",
    "/BitacoraSanciones",
    "/AsignacionMesas",
    "/AsignacionEquipo",
    "/Alta",
    "/AgregarTiempo",
    "/ActivosMantenimiento",
  ],
};
//IO