// Browser-safe slug helpers (zero dependencies) so the admin can validate slugs
// inline with the exact same rules the server publish gate enforces.
export { SLUG_PATTERN, RESERVED_SLUGS, normalizeSlug, isValidSlug, isReservedSlug, validateSlug, } from './content/slug.js';
/** Create a typed CMS client for frontend data access. */
export function createCMSClient(baseUrl, apiKey) {
    const headers = {
        'Content-Type': 'application/json',
    };
    if (apiKey)
        headers['Authorization'] = `Bearer ${apiKey}`;
    async function fetchApi(path) {
        const response = await fetch(`${baseUrl}${path}`, { headers });
        if (!response.ok) {
            throw new Error(`CMS API error: ${response.status} ${response.statusText}`);
        }
        return response.json();
    }
    return {
        collection(slug) {
            return {
                async find(options) {
                    const params = new URLSearchParams();
                    if (options?.page)
                        params.set('page', String(options.page));
                    if (options?.pageSize)
                        params.set('pageSize', String(options.pageSize));
                    if (options?.sort)
                        params.set('sort', options.sort);
                    if (options?.order)
                        params.set('order', options.order);
                    if (options?.locale)
                        params.set('locale', options.locale);
                    const qs = params.toString();
                    return fetchApi(`/api/collections/${slug}${qs ? `?${qs}` : ''}`);
                },
                async findById(id) {
                    return fetchApi(`/api/collections/${slug}/${id}`);
                },
                async findBySlug(slugValue) {
                    return fetchApi(`/api/collections/${slug}/slug/${slugValue}`);
                },
            };
        },
        global(slug) {
            return {
                async get() {
                    return fetchApi(`/api/globals/${slug}`);
                },
            };
        },
        async resolve(path) {
            return fetchApi(`/resolve?path=${encodeURIComponent(path)}`);
        },
    };
}
//# sourceMappingURL=client.js.map