import * as Blockly from 'blockly';
import CategoryColors from './define_color'

Blockly.Blocks.tuple_create_with_items_insert = {
    init: function () {
        this.setHelpUrl(Blockly.Msg.TUPLE_CREATE_WITH_ITEMS_INSERT_HELPURL);
        this.setColour(CategoryColors.Tuple);
        this.itemCount_ = 3;
        this.updateShape_();
        this.setOutput(!0);
        this.setMutator(new Blockly.icons.MutatorIcon(["tuple_create_with_item"],this));
        this.setTooltip(Blockly.Msg.TUPLE_CREATE_WITH_ITEMS_INSERT_TOOLTIP)
    },
    mutationToDom: function () {
        var a = document.createElement("mutation");
        a.setAttribute("items", this.itemCount_);
        return a
    },
    domToMutation: function (a) {
        this.itemCount_ = parseInt(a.getAttribute("items"), 10);
        this.updateShape_()
    },
    decompose: function (a) {
        var b = a.newBlock("tuple_create_with_container");
        b.initSvg();
        for (var c = b.getInput("STACK").connection, e = 0; e < this.itemCount_; e++) {
            var d = a.newBlock("tuple_create_with_item");
            d.initSvg();
            c.connect(d.previousConnection);
            c = d.nextConnection
        }
        return b
    },
    compose: function (a) {
        var b = a.getInputTargetBlock("STACK");
        for (a = []; b;)
            a.push(b.valueConnection_),
                b = b.nextConnection && b.nextConnection.targetBlock();
        for (b = 0; b < this.itemCount_; b++) {
            var c = this.getInput("ADD" + b).connection.targetConnection;
            c && -1 == a.indexOf(c) && c.disconnect()
        }
        this.itemCount_ = a.length;
        this.updateShape_();
        for (b = 0; b < this.itemCount_; b++)
            Blockly.icons.MutatorIcon.reconnect(a[b], this, "ADD" + b)
    },
    saveConnections: function (a) {
        a = a.getInputTargetBlock("STACK");
        for (var b = 0; a;) {
            var c = this.getInput("ADD" + b);
            a.valueConnection_ = c && c.connection.targetConnection;
            b++;
            a = a.nextConnection && a.nextConnection.targetBlock()
        }
    },
    updateShape_: function () {
        this.itemCount_ && this.getInput("EMPTY") ? this.removeInput("EMPTY") : this.itemCount_ || this.getInput("EMPTY") || this.appendDummyInput("EMPTY").appendField(Blockly.Msg.TUPLE_CREATE_EMPTY_TITLE);
        for (var a = 0; a < this.itemCount_; a++)
            if (!this.getInput("ADD" + a)) {
                var b = this.appendValueInput("ADD" + a);
                0 == a && b.appendField(Blockly.Msg.TUPLE_CREATE_WITH_INPUT_WITH)
            }
        for (; this.getInput("ADD" + a);)
            this.removeInput("ADD" + a),
                a++
    }
};
Blockly.Blocks.tuple_create_with_item = {
    init: function () {
        this.setColour(CategoryColors.Tuple);
        this.appendDummyInput().appendField(Blockly.Msg.TUPLE_CREATE_WITH_ITEM_TITLE);
        this.setPreviousStatement(!0);
        this.setNextStatement(!0);
        this.setTooltip(Blockly.Msg.TUPLE_CREATE_WITH_ITEM_TOOLTIP);
        this.contextMenu = !1
    }
};
Blockly.Blocks.tuple_create_with_container = {
    init: function () {
        this.setColour(CategoryColors.Tuple);
        this.appendDummyInput().appendField(Blockly.Msg.TUPLE_CREATE_WITH_CONTAINER_TITLE_ADD);
        this.appendStatementInput("STACK");
        this.setTooltip(Blockly.Msg.TUPLE_CREATE_WITH_CONTAINER_TOOLTIP);
        this.contextMenu = !1
    }
};
Blockly.Blocks.text_tuple = {
    init: function () {
        this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);
        this.setColour(192);
        this.appendDummyInput().appendField(Blockly.Msg.TEXT_TUPLE_START).appendField(new Blockly.FieldTextInput(""), "TEXT").appendField(Blockly.Msg.TEXT_TUPLE_END);
        this.setOutput(!0, "Array");
        this.setTooltip(Blockly.Msg.Text_Tuple_TOOLTIP);
    }
};
Blockly.Blocks.tuple_create_with = {
    init: function () {
        this.jsonInit({
            colour: CategoryColors.Tuple,
            args0: [{
                type: "input_value",
                name: "tuple_name"
            }, {
                type: "input_value",
                name: "tuple_items"
            }],
            inputsInline: !0,
            nextStatement: null,
            previousStatement: null,
            helpUrl: Blockly.Msg.tuple_create_with_HELPURL,
            tooltip: Blockly.Msg.tuple_create_with_TOOLTIP,
            message0: Blockly.Msg.tuple_create_with_MESSAGE0
        })
    }
};
Blockly.Blocks.tuple_order_item = {
    init: function () {
        this.jsonInit({
            colour: CategoryColors.Tuple,
            args0: [{
                type: "input_value",
                name: "tuple_name"
            }, {
                options: [
                    [Blockly.Msg.CocoRobo_ORDER, "["],
                    [Blockly.Msg.CocoRobo_REVERSE_ORDER, "[-"]
                ],
                type: "field_dropdown",
                name: "tuple_order"
            }, {
                check: "Number",
                type: "input_value",
                name: "tuple_order_item"
            }],
            output: ["Number", "String", "Boolean", "Array"],
            inputsInline: !0,
            helpUrl: Blockly.Msg.tuple_order_item_HELPURL,
            tooltip: Blockly.Msg.tuple_order_item_TOOLTIP,
            message0: Blockly.Msg.tuple_order_item_MESSAGE0
        })
    }
};
Blockly.Blocks.tuple_min_max_len = {
    init: function () {
        this.jsonInit({
            colour: CategoryColors.Tuple,
            args0: [{
                type: "input_value",
                name: "tuple_name"
            }, {
                options: [
                    [Blockly.Msg.CocoRobo_MIN, "min"],
                    [Blockly.Msg.CocoRobo_MAX, "max"],
                    [Blockly.Msg.CocoRobo_LENTH, "len"]
                ],
                type: "field_dropdown",
                name: "tuple_min_max_len"
            }],
            output: ["Number", "String"],
            inputsInline: !0,
            helpUrl: Blockly.Msg.TUPLE_MIN_MAX_LEN_HELPURL,
            // tooltip: Blockly.Msg.TUPLE_MIN_MAX_LEN_TOOLTIP,
            message0: Blockly.Msg.TUPLE_MIN_MAX_LEN_MESSAGE0
        });
        var thisBlock = this;
        this.setTooltip(function () {
            var mode = thisBlock.getFieldValue('tuple_min_max_len');
            var TOOLTIPS = {
                'min': Blockly.Msg.TUPLE_MIN_MAX_LEN_TOOLTIP.replace('%2', Blockly.Msg.CocoRobo_MIN),
                'max': Blockly.Msg.TUPLE_MIN_MAX_LEN_TOOLTIP.replace('%2', Blockly.Msg.CocoRobo_MAX),
                'len': Blockly.Msg.TUPLE_MIN_MAX_LEN_TOOLTIP.replace('%2', Blockly.Msg.CocoRobo_LENTH)
            };
            return TOOLTIPS[mode];
        });
    }
};
Blockly.Blocks.tuple_item_exist = {
    init: function () {
        this.jsonInit({
            colour: CategoryColors.Tuple,
            args0: [{
                type: "input_value",
                name: "tuple_name"
            }, {
                type: "input_value",
                name: "tuple_item"
            }],
            output: "Boolean",
            inputsInline: !0,
            helpUrl: Blockly.Msg.TUPLE_ITEM_EXIST_HELPURL,
            tooltip: Blockly.Msg.TUPLE_ITEM_EXIST_TOOLTIP,
            message0: Blockly.Msg.TUPLE_ITEM_EXIST_MESSAGE0
        })
    }
};
Blockly.Blocks.parts_of_tuple = {
    init: function () {
        this.jsonInit({
            colour: CategoryColors.Tuple,
            args0: [{
                type: "input_value",
                name: "tuple_name"
            }, {
                check: "Number",
                type: "input_value",
                name: "tuple_item"
            }],
            output: null,
            inputsInline: !0,
            helpUrl: Blockly.Msg.PARTS_OF_TUPLE_HELPURL,
            tooltip: Blockly.Msg.PARTS_OF_TUPLE_TOOLTIP,
            message0: Blockly.Msg.PARTS_OF_TUPLE_MESSAGE0
        })
    }
};
Blockly.Blocks.parts_of_tuple2 = {
    init: function () {
        this.jsonInit({
            colour: CategoryColors.Tuple,
            args0: [{
                type: "input_value",
                name: "tuple_name"
            }, {
                options: [
                    [Blockly.Msg.CocoRobo_ORDER, "["],
                    [Blockly.Msg.CocoRobo_REVERSE_ORDER, "[-"]
                ],
                type: "field_dropdown",
                name: "tuple_start_order"
            }, {
                check: "Number",
                type: "input_value",
                name: "start_item"
            }, {
                options: [
                    [Blockly.Msg.CocoRobo_ORDER, ":"],
                    [Blockly.Msg.CocoRobo_REVERSE_ORDER, ":-"]
                ],
                type: "field_dropdown",
                name: "tuple_end_order"
            }, {
                check: "Number",
                type: "input_value",
                name: "end_item"
            }],
            output: null,
            inputsInline: !0,
            helpUrl: Blockly.Msg.PARTS_OF_TUPLE2_HELPURL,
            tooltip: Blockly.Msg.PARTS_OF_TUPLE2_TOOLTIP,
            message0: Blockly.Msg.PARTS_OF_TUPLE2_MESSAGE0
        })
    }
};


export default Blockly;