import "../../../../dialect-helpers-DRI5pyY3.mjs";
import "../../../../base64-CmWvODNW.mjs";
import "../../../../types-CuW0zWDA.mjs";
import "../../../../fts-manager-BbFaF_V8.mjs";
import "../../../../loader-CB6YHeul.mjs";
import { n as apiSuccess, r as handleError, t as apiError } from "../../../../error-CkAseSqZ.mjs";
import { i as parseQuery, t as isParseError } from "../../../../parse-GmjecGct.mjs";
import { N as searchSuggestQuery } from "../../../../redirects-DXEXBAII.mjs";
import "../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../status-CqJQX1QN.mjs";
import "../../../../api/schemas/index.mjs";
import { a as getSuggestions } from "../../../../search-DZN2HZ-V.mjs";

//#region src/astro/routes/api/search/suggest.ts
const prerender = false;
/**
* Get search suggestions for autocomplete
*
* Query parameters:
* - q: Partial search query (required)
* - collections: Comma-separated list of collection slugs (optional)
* - limit: Maximum suggestions (optional, defaults to 5)
*/
const GET = async ({ url, locals }) => {
	const { emdash } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash not configured", 500);
	const query = parseQuery(url, searchSuggestQuery);
	if (isParseError(query)) return query;
	const collections = query.collections ? query.collections.split(",").map((c) => c.trim()) : void 0;
	try {
		await emdash.ensureSearchHealthy?.();
		return apiSuccess({ items: await getSuggestions(emdash.db, query.q, {
			collections,
			locale: query.locale,
			limit: query.limit
		}) });
	} catch (error) {
		return handleError(error, "Failed to get suggestions", "SUGGESTION_ERROR");
	}
};

//#endregion
export { GET, prerender };
//# sourceMappingURL=suggest.mjs.map