import { pythonGenerator } from "blockly/python";

const Blockly = {
    Python: pythonGenerator || { Msg: Object.create(null) }
};
Blockly.Python.text_dict = function (a) {
    return ["{" + Blockly.Python.quote_empty(a.getFieldValue("TEXT")) + "}", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.dict_create_with = function(a) {
    var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
    return b + " \x3d " + a + "\n"
};
Blockly.Python.dict_key_value = function(a) {
    var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
    return [b + ".get(" + a + ")", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.add_dict_key_value = function(a) {
    var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC),
        c = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
    a = Blockly.Python.valueToCode(a, "add_value", Blockly.Python.ORDER_ATOMIC);
    return b + "[" + c + "] \x3d " + a + "\n"
};
Blockly.Python.dict_length = function(a) {
    return ["len(" + Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.dict_key_exist = function(a) {
    var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
    return [Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.dict_key_or_val_list = function(a) {
    var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
    a = a.getFieldValue("key_or_val");
    return ["list(" + b + "." + a + "())", Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.dict_create_with_items_insert = function() {
    for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
        var c = this.getFieldValue("KEY" + b);
        a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
    }
    a = "{" + a.join(", ") + "}";
    return [a, Blockly.Python.ORDER_ATOMIC]
};
Blockly.Python.pinyin_dict_create_with_items_insert = function() {
    for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
        var c = this.getFieldValue("KEY" + b);
        a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
    }
    a = "{" + a.join(", ") + "}";
    return [a, Blockly.Python.ORDER_ATOMIC]
};




export default Blockly;