import { jsx as _jsx } from "react/jsx-runtime";
import { useUserSession } from "@vertesia/ui/session";
import { DocumentSearchResultsWithDropZone, DocumentSearchResults } from "../objects/DocumentSearchResults";
import { useToast } from "@vertesia/ui/core";
import { useDocumentSearch } from "../objects/search/DocumentSearchContext";
export function BrowseCollectionView({ collection }) {
    const toast = useToast();
    const { client, typeRegistry } = useUserSession();
    const search = useDocumentSearch();
    search.query.all_revisions = true;
    const onUploadDone = async (objectIds) => {
        if (objectIds.length > 0) {
            await client.store.collections.addMembers(collection.id, objectIds).catch(err => {
                toast({
                    title: 'Failed to add objects to collection',
                    description: err.message,
                    status: 'error'
                });
            });
        }
    };
    const tableLayout = getTableLayout(collection, typeRegistry);
    return collection.dynamic ? (_jsx(DocumentSearchResults, { layout: tableLayout })) : (_jsx(DocumentSearchResultsWithDropZone, { onUploadDone: onUploadDone, layout: tableLayout }));
}
function getTableLayout(collection, typeRegistry) {
    let table_layout = collection.table_layout;
    if (table_layout && table_layout.length > 0) {
        return table_layout;
    }
    if (collection.type && typeRegistry) {
        table_layout = typeRegistry?.getTypeLayout(collection.type.id);
    }
    if (table_layout && table_layout.length > 0) {
        return table_layout;
    }
    else {
        return undefined;
    }
}
//# sourceMappingURL=BrowseCollectionView.js.map