(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["chunks/[root-of-the-server]__f3e239ba._.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]/Desktop/Aynnaka/DiffaTours-main 2/src/middleware.ts [middleware-edge] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "config",
    ()=>config,
    "default",
    ()=>__TURBOPACK__default__export__
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f40$clerk$2f$nextjs$2f$dist$2f$esm$2f$server$2f$clerkMiddleware$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/node_modules/@clerk/nextjs/dist/esm/server/clerkMiddleware.js [middleware-edge] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f40$clerk$2f$nextjs$2f$dist$2f$esm$2f$server$2f$routeMatcher$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/node_modules/@clerk/nextjs/dist/esm/server/routeMatcher.js [middleware-edge] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$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]/Desktop/Aynnaka/DiffaTours-main 2/node_modules/next/dist/esm/api/server.js [middleware-edge] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$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]/Desktop/Aynnaka/DiffaTours-main 2/node_modules/next/dist/esm/server/web/exports/index.js [middleware-edge] (ecmascript)");
;
;
const isPublicRoute = (0, __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f40$clerk$2f$nextjs$2f$dist$2f$esm$2f$server$2f$routeMatcher$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["createRouteMatcher"])([
    '/',
    '/fr(.*)',
    '/en(.*)',
    '/es(.*)',
    '/it(.*)',
    '/sign-in(.*)',
    '/sign-up(.*)',
    '/api(.*)'
]);
const locales = [
    'fr',
    'en',
    'es',
    'it'
];
const defaultLocale = 'fr';
function getPreferredLocale(req) {
    // 1. Check for locale cookie
    const localeCookie = req.cookies.get('NEXT_LOCALE')?.value;
    if (localeCookie && locales.includes(localeCookie)) {
        return localeCookie;
    }
    // 2. Check Accept-Language header
    const acceptLanguage = req.headers.get('accept-language');
    if (acceptLanguage) {
        const preferredLang = acceptLanguage.split(',')[0].split('-')[0].toLowerCase();
        if (locales.includes(preferredLang)) {
            return preferredLang;
        }
    }
    // 3. Fallback to default locale
    return defaultLocale;
}
const __TURBOPACK__default__export__ = (0, __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f40$clerk$2f$nextjs$2f$dist$2f$esm$2f$server$2f$clerkMiddleware$2e$js__$5b$middleware$2d$edge$5d$__$28$ecmascript$29$__["clerkMiddleware"])(async (auth, req)=>{
    const { pathname } = req.nextUrl;
    // If visiting root path, redirect to preferred locale
    if (pathname === '/') {
        const preferredLocale = getPreferredLocale(req);
        const url = req.nextUrl.clone();
        url.pathname = `/${preferredLocale}`;
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$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(url);
    }
    // Redirect /sign-up and /sign-in to localized versions
    if (pathname === '/sign-up' || pathname.startsWith('/sign-up/')) {
        const preferredLocale = getPreferredLocale(req);
        const url = req.nextUrl.clone();
        const restOfPath = pathname.slice('/sign-up'.length);
        url.pathname = `/${preferredLocale}/sign-up${restOfPath}`;
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$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(url);
    }
    if (pathname === '/sign-in' || pathname.startsWith('/sign-in/')) {
        const preferredLocale = getPreferredLocale(req);
        const url = req.nextUrl.clone();
        const restOfPath = pathname.slice('/sign-in'.length);
        url.pathname = `/${preferredLocale}/sign-in${restOfPath}`;
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$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(url);
    }
    if (!isPublicRoute(req)) {
        await auth.protect();
    }
    // Get the response
    const response = __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$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();
    // Store current locale in cookie for future visits
    const currentLocale = pathname.split('/')[1];
    if (locales.includes(currentLocale)) {
        response.cookies.set('NEXT_LOCALE', currentLocale, {
            maxAge: 60 * 60 * 24 * 365,
            path: '/'
        });
    }
    // Remove Clerk's X-Frame-Options header to allow iframe embedding
    response.headers.delete('X-Frame-Options');
    // Set permissive CSP for iframe embedding
    response.headers.set('Content-Security-Policy', "frame-ancestors 'self' https://*.orchids.app http://*.orchids.app https://www.orchids.app http://www.orchids.app");
    return response;
});
const config = {
    matcher: [
        '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)'
    ]
};
}),
]);

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