// import { NextRequest, NextResponse } from 'next/server';
// const privateRoutes = ['/addcustomer/', '/manage-orders/'];

// console.log("middleware trgggered before")

// export function middleware(request: NextRequest) {
//   console.log("middleware trgggered after")
//   const token = request.cookies.get('userToken');
//   const path = request.nextUrl.pathname;
//   console.log(token,"token found")
//   const url = request.nextUrl.clone();

//   if (privateRoutes.includes(path) && !token) {
//     return NextResponse.redirect(new URL('/', request.url)); // Redirect to the public route if the token is missing
//   }
//   if ((url.pathname === '/' && token) || (privateRoutes.includes(url.pathname) && !token)) {
//     // Redirect to /addcustomer/ if the path is '/' and there is a token
//     // Redirect to the public route if the token is missing for other private routes
//     return NextResponse.redirect(new URL(token ? '/addcustomer/' : '/', request.url));
//   }

//   return NextResponse.next(); // Proceed to the intended route
// }

// export const config = {
//   matcher: ['/addcustomer/', '/manage-orders/'], // Apply middleware only to these routes
// };