/* eslint-disable no-unused-expressions */
import * as Blockly from 'blockly';
import CategoryColors from './define_color'

Blockly.Blocks.set_create_with_items_insert = {
    init: function () {
        this.setHelpUrl(Blockly.Msg.SET_CREATE_WITH_ITEMS_INSERT_HELPURL);
        this.setColour(CategoryColors.Set);
        this.itemCount_ = 3;
        this.updateShape_();
        this.setOutput(!0, "Array");
        this.setMutator(new Blockly.icons.MutatorIcon(["set_create_with_item"],this));
        this.setTooltip(Blockly.Msg.SET_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("set_create_with_container");
        b.initSvg();
        for (var c = b.getInput("STACK").connection, e = 0; e < this.itemCount_; e++) {
            var d = a.newBlock("set_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.SET_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.SET_CREATE_WITH_INPUT_WITH)
            }
        for (; this.getInput("ADD" + a);)
            this.removeInput("ADD" + a),
                a++
    }
};
Blockly.Blocks.set_create_with_item = {
    init: function () {
        this.setColour(CategoryColors.Set);
        this.appendDummyInput().appendField(Blockly.Msg.SET_CREATE_WITH_ITEM_TITLE);
        this.setPreviousStatement(!0);
        this.setNextStatement(!0);
        this.setTooltip(Blockly.Msg.SET_CREATE_WITH_ITEM_TOOLTIP);
        this.contextMenu = !1
    }
};
Blockly.Blocks.set_create_with_container = {
    init: function () {
        this.setColour(CategoryColors.Set);
        this.appendDummyInput().appendField(Blockly.Msg.SET_CREATE_WITH_CONTAINER_TITLE_ADD);
        this.appendStatementInput("STACK");
        this.setTooltip(Blockly.Msg.SET_CREATE_WITH_CONTAINER_TOOLTIP);
        this.contextMenu = !1
    }
};
Blockly.Blocks.text_set = {
    init: function () {
        this.setHelpUrl(Blockly.Msg.TEXT_SET_HELPURL);
        this.setColour(CategoryColors.Set);
        this.appendDummyInput().appendField(Blockly.Msg.TEXT_SET_START).appendField(new Blockly.FieldTextInput(""), "TEXT").appendField(Blockly.Msg.TEXT_SET_END);
        this.setOutput(!0, "Array");
        this.setTooltip(Blockly.Msg.Text_Set_TOOLTIP);
    }
};
Blockly.Blocks.set_create_with = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            nextStatement: null,
            previousStatement: null,
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.SET_CREATE_WITH_HELPURL,
            tooltip: Blockly.Msg.SET_CREATE_WITH_TOOLTIP,
            message0: Blockly.Msg.SET_CREATE_WITH_MESSAGE0,
            args0: [{
                type: "input_value",
                name: "set_name"
            }, {
                type: "input_value",
                name: "set_items"
            }]
        })
    }
};
Blockly.Blocks.sets_update_ways = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            nextStatement: null,
            previousStatement: null,
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.SETS_UPDATE_WAYS_HELPURL,
            // tooltip: Blockly.Msg.SETS_UPDATE_WAYS_TOOLTIP,
            message0: Blockly.Msg.SETS_UPDATE_WAYS_MESSAGE0,
            args0: [{
                type: "input_value",
                name: "set_name"
            }, {
                type: "input_value",
                name: "set_1_name"
            }, {
                options: [
                    [Blockly.Msg.CocoRobo_INTERSECTION, ".intersection_update"],
                    [Blockly.Msg.CocoRobo_UNION, ".update"],
                    [Blockly.Msg.CocoRobo_DIFFERENCE, ".difference_update"]
                ],
                type: "field_dropdown",
                name: "sets_update_ways"
            }]
        });
        var thisBlock = this;
        this.setTooltip(function () {
            var mode = thisBlock.getFieldValue('sets_update_ways');
            var TOOLTIPS = {
                '.intersection_update': Blockly.Msg.SETS_UPDATE_WAYS_TOOLTIP.replace('%3', Blockly.Msg.CocoRobo_INTERSECTION),
                '.update': Blockly.Msg.SETS_UPDATE_WAYS_TOOLTIP.replace('%3', Blockly.Msg.CocoRobo_UNION),
                '.difference_update': Blockly.Msg.SETS_UPDATE_WAYS_TOOLTIP.replace('%3', Blockly.Msg.CocoRobo_DIFFERENCE)
            };
            return TOOLTIPS[mode];
        });
    }
};
Blockly.Blocks.get_sets_pop = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            output: null,
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.GET_SETS_POP_HELPURL,
            tooltip: Blockly.Msg.GET_SETS_POP_TOOLTIP,
            message0: Blockly.Msg.GET_SETS_POP_MESSAGE0,
            args0: [{
                type: "input_value",
                name: "set_name"
            }]
        })
    }
};
Blockly.Blocks.len_of_sets = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            output: "Number",
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.LEN_OF_SETS_HELPURL,
            tooltip: Blockly.Msg.LEN_OF_SETS_TOOLTIP,
            message0: Blockly.Msg.LEN_OF_SETS_MESSAGE0,
            args0: [{
                type: "input_value",
                name: "set_name"
            }]
        })
    }
};
Blockly.Blocks.intersection_of_sets = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            output: "Array",
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.INTERSECTION_OF_SETS_HELPURL,
            // tooltip: Blockly.Msg.INTERSECTION_OF_SETS_TOOLTIP,
            message0: Blockly.Msg.INTERSECTION_OF_SETS_MESSAGE0,
            args0: [{
                options: [
                    [Blockly.Msg.CocoRobo_INTERSECTION, " \x26 "],
                    [Blockly.Msg.CocoRobo_UNION, " | "],
                    [Blockly.Msg.CocoRobo_DIFFERENCE, " - "]
                ],
                type: "field_dropdown",
                name: "set_operation_type"
            }, {
                type: "input_value",
                name: "set_name"
            }, {
                type: "input_value",
                name: "set_1_name"
            }]
        });
        var thisBlock = this;
        this.setTooltip(function () {
            var mode = thisBlock.getFieldValue('set_operation_type');
            var TOOLTIPS = {
                " \x26 ": Blockly.Msg.INTERSECTION_OF_SETS_TOOLTIP.replace('%1', Blockly.Msg.CocoRobo_INTERSECTION),
                " | ": Blockly.Msg.INTERSECTION_OF_SETS_TOOLTIP.replace('%1', Blockly.Msg.CocoRobo_UNION),
                " - ": Blockly.Msg.INTERSECTION_OF_SETS_TOOLTIP.replace('%1', Blockly.Msg.CocoRobo_DIFFERENCE)
            };
            return TOOLTIPS[mode];
        });
    }
};
Blockly.Blocks.set_update_with = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            nextStatement: null,
            previousStatement: null,
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.SET_UPDATE_WITH_HELPURL,
            tooltip: Blockly.Msg.SET_UPDATE_WITH_TOOLTIP,
            message0: Blockly.Msg.SET_UPDATE_WITH_MESSAGE0,
            args0: [{
                type: "input_value",
                name: "set_name"
            }, {
                type: "input_value",
                name: "set_items"
            }]
        })
    }
};
Blockly.Blocks.set_subset_superset = {
    init: function () {
        this.jsonInit({
            inputsInline: !0,
            output: "Boolean",
            colour: CategoryColors.Set,
            helpUrl: Blockly.Msg.SUBSET_SUPERSET_HELPURL,
            // tooltip: Blockly.Msg.SUBSET_SUPERSET_TOOLTIP,
            message0: Blockly.Msg.SUBSET_SUPERSET_MESSAGE0,
            args0: [{
                type: "input_value",
                name: "set_name"
            }, {
                type: "input_value",
                name: "set_1_name"
            }, {
                options: [
                    [Blockly.Msg.CocoRobo_SUBSET, ".issubset"],
                    [Blockly.Msg.CocoRobo_SUPERSET, ".issuperset"]
                ],
                type: "field_dropdown",
                name: "subset_superset"
            }]
        });
        var thisBlock = this;
        this.setTooltip(function () {
            var mode = thisBlock.getFieldValue('subset_superset');
            var TOOLTIPS = {
                '.issubset': Blockly.Msg.SUBSET_SUPERSET_TOOLTIP.replace('%3', Blockly.Msg.CocoRobo_SUBSET),
                '.issuperset': Blockly.Msg.SUBSET_SUPERSET_TOOLTIP.replace('%3', Blockly.Msg.CocoRobo_SUPERSET)
            };
            return TOOLTIPS[mode];
        });
    }
};

export default Blockly