(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["chunks/[root-of-the-server]__f2b15f93._.js",
"[externals]/node:buffer [external] (node:buffer, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("node:buffer", () => require("node:buffer"));

module.exports = mod;
}),
"[externals]/node:async_hooks [external] (node:async_hooks, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("node:async_hooks", () => require("node:async_hooks"));

module.exports = mod;
}),
"[project]/middleware.ts [middleware-edge] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "config",
    ()=>config,
    "middleware",
    ()=>middleware
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$api$2f$server$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/node_modules/next/dist/esm/api/server.js [middleware-edge] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/next/dist/esm/server/web/exports/index.js [middleware-edge] (ecmascript)");
;
const BOT_USER_AGENT_KEYWORDS = [
    "googlebot",
    "adsbot-google",
    "bingbot",
    "slurp",
    "duckduckbot",
    "baiduspider",
    "yandexbot",
    "sogou",
    "exabot",
    "facebot",
    "ia_archiver"
];
// Sensitive parameters that must be stripped for bots/crawlers
const SENSITIVE_PARAMS = [
    "gclid",
    "gad_source",
    "gad_campaignid",
    "gbraid",
    "wbraid",
    "gclsrc"
];
// Google Ads parameters that need to be persisted in cookies
const PERSISTENT_PARAMS = [
    "gad_campaignid",
    "gad_source",
    "gclid",
    "gbraid",
    "wbraid"
];
const GOOGLE_ADS_PARAMS_COOKIE = "google-ads-params";
const COOKIE_MAX_AGE = 60 * 60 * 24; // 24 hours
/**
 * Checks if the request is from a bot/crawler
 */ function isBot(userAgent) {
    return BOT_USER_AGENT_KEYWORDS.some((keyword)=>userAgent.includes(keyword));
}
function middleware(request) {
    try {
        const url = request.nextUrl.clone();
        const hostname = request.headers.get("host") || "";
        // Extract subdomain from hostname (e.g., "admin.example.com" -> "admin")
        const subdomain = hostname.split(".")[0];
        const isAdminSubdomain = subdomain === "admin";
        const isAdminPath = url.pathname.startsWith("/admin");
        // If on admin subdomain, handle admin routing
        if (isAdminSubdomain) {
            // If accessing root path on admin subdomain, rewrite to /admin page
            if (url.pathname === "/" || url.pathname === "") {
                const rewriteUrl = url.clone();
                rewriteUrl.pathname = "/admin";
                return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].rewrite(rewriteUrl);
            }
            // Allow all other paths (API routes, _next, etc.) - skip bot detection
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
        }
        // If accessing /admin on main domain, redirect to admin subdomain
        if (isAdminPath) {
            // Detect protocol (check x-forwarded-proto first, then use https as default)
            const protocol = request.headers.get("x-forwarded-proto") || (request.url.startsWith("https") ? "https" : "http");
            // Extract main domain (handle port if present)
            const mainDomain = hostname.includes(":") ? hostname.split(":")[0] : hostname;
            // Build admin subdomain URL
            const adminDomain = `admin.${mainDomain}`;
            const port = hostname.includes(":") ? `:${hostname.split(":")[1]}` : "";
            const pathWithoutAdmin = url.pathname.replace("/admin", "") || "/";
            const redirectUrl = `${protocol}://${adminDomain}${port}${pathWithoutAdmin}${url.search}`;
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].redirect(redirectUrl, 301);
        }
        const userAgent = request.headers.get("user-agent")?.toLowerCase() ?? "";
        const isBotRequest = isBot(userAgent);
        const visitorType = isBotRequest ? "bot" : "human";
        const requestHeaders = new Headers(request.headers);
        requestHeaders.set("x-visitor-type", visitorType);
        // For bots/crawlers: Strip sensitive parameters from the URL to prevent indexing
        // This ensures search engines never see Google Ads parameters, mobile flags, etc.
        if (isBotRequest && request.nextUrl.searchParams.size > 0) {
            const cleanUrl = request.nextUrl.clone();
            // Remove all sensitive parameters
            SENSITIVE_PARAMS.forEach((param)=>{
                cleanUrl.searchParams.delete(param);
            });
            // Redirect bots to clean URL (301 permanent redirect for SEO)
            // This ensures bots never index URLs with sensitive params
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].redirect(cleanUrl, {
                status: 301,
                headers: requestHeaders
            });
        }
        // Persist Google Ads parameters in cookie for non-bot requests
        const response = __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next({
            request: {
                headers: requestHeaders
            }
        });
        // Check if request has Google Ads parameters to persist
        const params = {};
        let hasAnyParam = false;
        for (const param of PERSISTENT_PARAMS){
            const value = request.nextUrl.searchParams.get(param);
            if (value) {
                params[param] = value;
                hasAnyParam = true;
            }
        }
        if (hasAnyParam) {
            // Store parameters in cookie as JSON
            response.cookies.set(GOOGLE_ADS_PARAMS_COOKIE, JSON.stringify(params), {
                path: "/",
                maxAge: COOKIE_MAX_AGE,
                sameSite: "lax",
                httpOnly: false,
                secure: ("TURBOPACK compile-time value", "development") === "production"
            });
        }
        return response;
    } catch (error) {
        // Fallback: return next response on error to prevent middleware failures
        console.error("Middleware error:", error);
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$dist$2f$esm$2f$server$2f$web$2f$exports$2f$index$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["NextResponse"].next();
    }
}
const config = {
    matcher: [
        /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     * - robots.txt (robots file)
     * - sitemap.xml (sitemap file)
     */ "/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml).*)"
    ]
};
}),
]);

//# sourceMappingURL=%5Broot-of-the-server%5D__f2b15f93._.js.map