import { pythonGenerator } from "blockly/python";

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

Blockly.Python.text_tuple = function (a) {
    return ["(" + Blockly.Python.quote_empty(a.getFieldValue("TEXT")) + ")", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.set_tuple_order_item = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
        c = a.getFieldValue("tuple_order"),
        d = Blockly.Python.valueToCode(a, "tuple_order_item", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
    return b + c + d + "] \x3d " + a + "\n"
};
Blockly.Python.tuple_create_with_items_insert = function(a) {
    for (var b = Array(a.itemCount_), c = 0; c < a.itemCount_; c++)
        b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
    return [1 == a.itemCount_ ? "(" + b[0] + ",)" : "(" + b.join(", ") + ")", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.tuple_create_with = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "tuple_items", Blockly.Python.ORDER_ATOMIC);
    return b + " \x3d " + a + "\n"
};
Blockly.Python.tuple_order_item = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
        c = a.getFieldValue("tuple_order");
    a = Blockly.Python.valueToCode(a, "tuple_order_item", Blockly.Python.ORDER_ATOMIC);
    return [b + c + a + "]", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.tuple_min_max_len = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
    return [a.getFieldValue("tuple_min_max_len") + "(" + b + ")", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.tuple_item_exist = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
    return [Blockly.Python.valueToCode(a, "tuple_item", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.parts_of_tuple = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "tuple_item", Blockly.Python.ORDER_ATOMIC);
    return [b + "[" + a + ":]", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.parts_of_tuple2 = function(a) {
    var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
        c = a.getFieldValue("tuple_start_order"),
        d = a.getFieldValue("tuple_end_order"),
        e = Blockly.Python.valueToCode(a, "start_item", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "end_item", Blockly.Python.ORDER_ATOMIC);
    switch (d) {
        case ":":
            var f = parseInt(a) + 1;
            break;
        case ":-":
            f = a - 1
    }
    return [b + c + e + d + f + "]", Blockly.Python.ORDER_ATOMIC]
};

export default Blockly;