import { jsx as _jsx } from "react/jsx-runtime";
import { useUserSession } from "@vertesia/ui/session";
import { useMemo } from "react";
import { DocumentSearch, SearchContext } from "./DocumentSearchContext";
export function DocumentSearchProvider({ children, limit, parent, typeId, facets, name, collectionId }) {
    const { store } = useUserSession();
    const search = useMemo(() => {
        let facetSpecs;
        if (facets) {
            facetSpecs = facets;
        }
        else {
            facetSpecs = [
                {
                    name: 'status',
                    field: 'status'
                },
                {
                    name: 'location',
                    field: 'location'
                }
            ];
            if (!typeId) {
                facetSpecs.unshift({
                    name: 'type',
                    field: 'type'
                });
            }
        }
        const search = new DocumentSearch(store, limit).withFacets(facetSpecs);
        search.collectionId = collectionId;
        search.query.type = typeId;
        search.query.parent = parent;
        search.query.name = name;
        return search;
    }, [typeId, limit, collectionId]);
    return (_jsx(SearchContext.Provider, { value: search, children: children }));
}
//# sourceMappingURL=DocumentSearchProvider.js.map