import * as Blockly from 'blockly';

export function getBlocksByTypeName(typeName: string) {
    let blocks: any = Blockly.Xml.workspaceToDom(window.blockly).getElementsByTagName('block');
    let filtersBlocks: any = []
    for (let i = 0; i < blocks.length; i++) {
        if (blocks[i].getAttribute("type") === typeName) {
            filtersBlocks.push(blocks[i]);
        }
    }
    return filtersBlocks;
}

export function getAllGobalVariables(block: any) {
    let allGobalList: any = [];
    try {
        let blocksList = block.workspace.getAllBlocks()[0].workspace.variableMap.variableMap
        blocksList.get("").map((item: any) => { allGobalList.push(item.name) })
    }
    catch (e) {
        return ""
    }
    return allGobalList.join(",")
}