/** Build a WHERE clause fragment for locale-filtered document queries. */
export function buildLocaleFilter(query) {
    const params = [query.locale];
    const conditions = [`"locale" = $1`];
    if (query.localeGroupId) {
        params.push(query.localeGroupId);
        conditions.push(`"localeGroupId" = $${params.length}`);
    }
    return { sql: conditions.join(' AND '), params };
}
/** Build a query that returns documents with a fallback to another locale. */
export function buildLocaleFallbackQuery(collection, locale, fallbackLocale) {
    return {
        sql: `
    SELECT DISTINCT ON ("localeGroupId") *
    FROM actuate_documents
    WHERE collection = $1
      AND "deletedAt" IS NULL
      AND locale IN ($2, $3)
    ORDER BY "localeGroupId",
      CASE WHEN locale = $2 THEN 0 ELSE 1 END
  `,
        params: [collection, locale, fallbackLocale],
    };
}
/** Get the available locales from the i18n config. */
export function getLocales(config) {
    return config.locales.map(({ code, label }) => ({ code, label }));
}
/** Resolve the effective locale, falling back to the default if necessary. */
export function resolveLocale(requested, config) {
    if (!requested)
        return config.defaultLocale;
    const exists = config.locales.some((l) => l.code === requested);
    return exists ? requested : (config.fallbackLocale ?? config.defaultLocale);
}
//# sourceMappingURL=index.js.map