import { P } from "ts-pattern";
import { revalidatePath, revalidateTag } from "next/cache";
import { NextRequest } from "next/server";
import { MAKESWIFT_CACHE_TAG } from "../../cache";
import { appRouterRedirectPreviewHandler } from "../handlers/app-router-redirect-preview";
import { MAKESWIFT_SITE_VERSION_COOKIE, PRERENDER_BYPASS_COOKIE } from "../preview";
import { validateApiRoute } from "./base";
const argsPattern = [
  P.union(P.instanceOf(Request), P.instanceOf(NextRequest)),
  P.any
];
async function config({
  req,
  context,
  client
}) {
  return {
    req,
    route: validateApiRoute(await context.params),
    previewCookieNames: [PRERENDER_BYPASS_COOKIE, MAKESWIFT_SITE_VERSION_COOKIE],
    sendResponse: async (res) => res,
    revalidationHandler: async (path) => {
      if (path != null) {
        revalidatePath(path);
      } else {
        revalidateTag(MAKESWIFT_CACHE_TAG);
      }
    },
    customRoutes: async (route) => {
      if (route === "/redirect-preview") {
        const request = req instanceof NextRequest ? req : new NextRequest(req, req);
        return { res: await appRouterRedirectPreviewHandler(request, context, client) };
      }
      return null;
    }
  };
}
export {
  argsPattern,
  config
};
//# sourceMappingURL=app-router.js.map