"use strict";
/**
 * WebSearch Type Definitions
 *
 * Contains all type definitions for WebSearch providers and status.
 *
 * @module utils/websearch/types
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeSearxngBaseUrl = void 0;
/**
 * Normalize a SearXNG base URL so runtime code can safely append `/search`.
 *
 * Accepts optional subpaths (for reverse-proxy deployments), strips a trailing
 * `/search` endpoint suffix, and rejects query/hash-bearing URLs because the
 * runtime owns the request path and query params.
 */
function normalizeSearxngBaseUrl(url) {
    const normalized = String(url || '').trim();
    if (!normalized) {
        return '';
    }
    try {
        const parsed = new URL(normalized);
        if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
            return null;
        }
        if (parsed.username || parsed.password) {
            return null;
        }
        if (parsed.search || parsed.hash) {
            return null;
        }
        let pathname = parsed.pathname.replace(/\/+$/, '');
        if (pathname.toLowerCase().endsWith('/search')) {
            pathname = pathname.slice(0, -'/search'.length);
        }
        parsed.pathname = pathname || '/';
        parsed.search = '';
        parsed.hash = '';
        return parsed.toString().replace(/\/+$/, '');
    }
    catch {
        return null;
    }
}
exports.normalizeSearxngBaseUrl = normalizeSearxngBaseUrl;
//# sourceMappingURL=types.js.map