import iterate from '../../fn/loop/iterate.js';
import isObject from '../../fn/type/isObject.js';
import isArray from '../../fn/type/isArray.js';
export default function fieldsFromFilter(filter, fields = []) {
    if (filter?.conditions?.length) {
        filter.conditions.forEach((cond) => {
            if (cond.field && !fields.includes(cond.field)) {
                fields.push(cond.field);
            }
            else if (cond.conditions) {
                fieldsFromFilter(cond, fields);
            }
        });
    }
    else if (isObject(filter)) {
        iterate(filter, (_v, n) => {
            if (!fields.includes(n)) {
                fields.push(n);
            }
        });
    }
    else if (isArray(filter)) {
        filter.forEach((cond) => {
            if (cond.field && !fields.includes(cond.field)) {
                fields.push(cond.field);
            }
            else if (cond.conditions) {
                fieldsFromFilter(cond, fields);
            }
        });
    }
    return fields;
}
