function modalEdges(cy){
    cy.edges().on('click', function(e){
        var current_edge = this;
        var src_tar_list = getSourcesTargets(current_edge)
        var edge_uuids = getUUIDs(current_edge)
        // console.log(src_tar_list);
        // console.log(edge_uuids)
        var sources = src_tar_list[0];
        var targets = src_tar_list[1];
        $('#edgeModal').modal('show')
        var sources_div = $('#edgeModal').find('.modal-body').find('.edgeModal-sources')[0]
        sources_div.innerHTML = null
        for (var s of sources){
            var source_button = document.createElement("button");
            source_button.classList.add('btn')
            source_button.classList.add('btn-default')
            source_button.classList.add('btn-src')
            source_button.textContent = s.data().name
            source_button.dataset.id = s.data().id
            sources_div.appendChild(source_button)
            sources_div.append(" ")
        }
        var targets_div = $('#edgeModal').find('.modal-body').find('.edgeModal-targets')[0]
        targets_div.innerHTML = null
        for (var t of targets){
            var target_button = document.createElement("button");
            target_button.classList.add('btn')
            target_button.classList.add('btn-default')
            target_button.classList.add('btn-targ')
            target_button.textContent = t.data().name
            target_button.dataset.id = t.data().id
            targets_div.appendChild(target_button)
            targets_div.append(" ")
                var f_uuids = filterUUIDs(s, t, this);
        }
        $(".btn-src").on('click', function(b){
            toggleButton(b.target)
            var f_uuids = getFilteredUUIDs(current_edge)
            console.log(f_uuids)
        })
        $(".btn-targ").on('click', function(b){
            toggleButton(b.target)
            var f_uuids = getFilteredUUIDs(current_edge)
            console.log(f_uuids)
        })
    })
}


function getSourcesTargets(edge){
    var sources = [];
    var source = edge.source();
    if (source.isParent()){
        console.log('source is compound');
        var children = source.children();
        children.forEach(function (child) {
            sources.push(child)
        })
    }
    else {
        sources.push(source);
    }
    var targets = [];
    var target = edge.target();
    if (target.isParent()){
        console.log('target is compound');
        var children = target.children();
        children.forEach(function (child) {
            targets.push(child)
        })
    }
    else {
        targets.push(target);
    }
    return [sources, targets];
}

function getUUIDs(ele){
    return ele.data().uuid_list
}

function filterUUIDs(e1, e2, e3){
    var s_uuids = new Set(e1.data().uuid_list);
    var t_uuids = new Set(e2.data().uuid_list);
    var e_uuids = new Set(e3.data().uuid_list);
    f_uuids = intersection(s_uuids, t_uuids);
    f_uuids = intersection(f_uuids, e_uuids);
    return f_uuids

}

function intersection(setA, setB) {
    var _intersection = new Set();
    for (var elem of setB) {
        if (setA.has(elem)) {
            _intersection.add(elem);
        }
    }
    return _intersection;
}

modalEdges(cy);

// statements.filter(st => st.id == "afb92699-ccad-4cef-a56c-adda79a7688a")


function toggleButton(button){
    var button_classes = ["btn-src", "btn-targ"];
    for (var button_class of button_classes){
        if ([...button.classList].indexOf(button_class) !== -1){
            var class_str = "." + button_class
            for (b of $(class_str)){
                b.classList.remove('active')
            }
        }
    }
    button.classList.add('active')
}

function getActiveButtons(){
    var src_active = $(".btn-src.active")[0]
    var targ_active = $(".btn-targ.active")[0]
    return [src_active, targ_active]
}

function getFilteredUUIDs(edge){
    var active_btns = getActiveButtons()
    var element_array = [edge, edge, edge]
    if (active_btns[0] !== undefined){
        element_array[0] = cy.getElementById(active_btns[0].dataset.id)
    }
    if (active_btns[1] !== undefined){
        element_array[1] = cy.getElementById(active_btns[1].dataset.id)
    }
    console.log(element_array)
    var filtered_uuids = filterUUIDs(...element_array)
    return filtered_uuids
}
@@ -3711,24 +3711,289 @@
 active')%0A%7D%0A%0A
+function deactivateAllButtons()%7B%0A    var button_classes = %5B%22btn-src%22, %22btn-targ%22%5D;%0A    for (var button_class of button_classes)%7B%0A        var class_str = %22.%22 + button_class%0A        for (b of $(class_str))%7B%0A            b.classList.remove('active')%0A        %7D%0A    %7D%0A%7D%0A%0A
 function get

add function for deactivating buttons