import { pythonGenerator } from "blockly/python";

const Blockly = {
    Python: pythonGenerator || { Msg: Object.create(null) }
};

Blockly.Python.set_create_with_items_insert = function(a) {
    var b = Array(a.itemCount_);
    if (0 == a.itemCount_)
        a = "set()";
    else {
        for (var c = 0; c < a.itemCount_; c++)
            b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
        a = "{" + b.join(", ") + "}"
    }
    return [a, Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.text_set = function(a) {
    return ["{" + Blockly.Python.quote_empty(a.getFieldValue("TEXT")) + "}", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.set_create_with = function(a) {
    var b = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "set_items", Blockly.Python.ORDER_ATOMIC);
    return b + " \x3d " + a + "\n"
};
Blockly.Python.sets_update_ways = function(a) {
    var b = a.getFieldValue("sets_update_ways"),
        c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
    return c + b + "(" + a + ")\n"
};
Blockly.Python.get_sets_pop = function(a) {
    return [Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + ".pop()", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.len_of_sets = function(a) {
    return ["len(" + Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.intersection_of_sets = function(a) {
    var b = a.getFieldValue("set_operation_type"),
        c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
    return [c + b + a, Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.set_update_with = function(a) {
    var b = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "set_items", Blockly.Python.ORDER_ATOMIC);
    return b + ".update(" + a + ")\n"
};
Blockly.Python.set_subset_superset = function(a) {
    var b = a.getFieldValue("subset_superset"),
        c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
    return [c + b + "(" + a + ")", Blockly.Python.ORDER_ATOMIC]
};

export default Blockly;