import { mergeFilter } from "./utils.mjs";
function mergeIncomingFiltersFromSourceBlocks(ownFilter, currentBlockUid, dataBlocks) {
    if (!currentBlockUid) return null != ownFilter ? ownFilter : {};
    const sources = dataBlocks.filter((b)=>{
        var _b_filterTargetUids;
        return (null == (_b_filterTargetUids = b.filterTargetUids) ? void 0 : _b_filterTargetUids.length) && b.filterTargetUids.includes(currentBlockUid);
    });
    const sourceFilters = sources.map((b)=>b.defaultFilter).filter((f)=>f && 'object' == typeof f && Object.keys(f).length > 0);
    if (!sourceFilters.length) return null != ownFilter ? ownFilter : {};
    const own = ownFilter && 'object' == typeof ownFilter ? ownFilter : {};
    return mergeFilter([
        ...sourceFilters,
        own
    ], '$and');
}
function getFilterSourceDefaultFilter(dataBlocks, filterSourceUid) {
    var _dataBlocks_find;
    if (!filterSourceUid) return {};
    const f = null == (_dataBlocks_find = dataBlocks.find((b)=>b.uid === filterSourceUid)) ? void 0 : _dataBlocks_find.defaultFilter;
    if (f && 'object' == typeof f && Object.keys(f).length) return f;
    return {};
}
export { getFilterSourceDefaultFilter, mergeIncomingFiltersFromSourceBlocks };
