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

export function middleware(request: NextRequest) {
  //   console.log(request.nextUrl.pathname.startsWith("/"), " middleware");
  const allCookies = request.cookies.toString();
  const hasCookie = request.cookies.has("auth");
  // console.log(hasCookie, " has set cookie ", allCookies);
  // if (allCookies === "") {
  //   if (request.nextUrl.pathname !== "/login") {
  //     return NextResponse.redirect(new URL("/login", request.url));
  //   }
  // } else {
  //   if (request.nextUrl.pathname === "/login") {
  //     return NextResponse.redirect(new URL("/customer", request.url));
  //   }
  // }

  // if (request.nextUrl.pathname.startsWith("/add-user")) {
  // return NextResponse.redirect(new URL("/", request.url));
  // }
  // if (request.nextUrl.pathname.startsWith("/dashboard")) {
  //   return NextResponse.rewrite(new URL("/dashboard/user", request.url));
  // }

  // if (data === undefined) {
  //   return NextResponse.redirect(new URL("/login", request.url));
  // }
}

export const config = {
  matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)"],
};
