// Find all linked projects
const goalPage = dv.page(input.file);
const projects = goalPage.file.inlinks.where((p) => {
    const mp = dv.page(p.path);
    return mp.tags?.includes("process/project");
});

const totalGoalTasks = goalPage.file.tasks.length;

let totalProjectTasks = 0;
let totalTasksTasks = 0;
let totalTasks = 0;
projects.values.reduce((acc, p) => {
    const mp = dv.page(p.path);
    const tasks = mp.file.tasks;

    const aufgaben = mp.file.inlinks.where((p) => {
        const mt = dv.page(p);
        return mt.tags?.includes("process/task");
    });
    let totalTasks = 0;
    aufgaben.values.reduce((act, t) => {
        const mt = dv.page(t.path);
        const t2 = mt.file.tasks;
        totalTasks += t2.length;
        return mt.file.tasks.length;
    }, 0);

    totalTasksTasks += totalTasks;
    totalProjectTasks += tasks.length;
    return mp.file.tasks.length;
}, 0);

dv.span(totalGoalTasks + totalProjectTasks + totalTasksTasks);
