// 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 totalGoalTasksCompleted = goalPage.file.tasks.where(t => t.fullyCompleted === true).length;

let totalProjectTasksCompleted = 0;
let totalTasksTasksCompleted = 0;
projects.values.reduce((acc, p) => {
    const mp = dv.page(p.path);
    totalProjectTasksCompleted += mp.file.tasks.where( (t) => t.fullyCompleted === true).length;

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

    return mp.file.tasks.length;
}, 0);

dv.span(totalGoalTasksCompleted + totalProjectTasksCompleted + totalTasksTasksCompleted);
