import type { MiddlewareHandler } from 'astro';
import { z } from 'zod';
import { he } from '@/lib/i18n/he';
import { en } from '@/lib/i18n/en';
import { setBundles } from '@/lib/i18n';
import { createZodErrorMap } from '@/lib/i18n/zod-error-map';

// Top-level: runs once when the Worker module loads, persists across requests.
// he.ts + en.ts are imported here (server-only module) — Vite will NOT include
// them in client island bundles since this file is only reachable from middleware.ts.
setBundles({ he, en });
z.config({ customError: createZodErrorMap('he') });

export const i18nMiddleware: MiddlewareHandler = (_ctx, next) => next();
