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

Blockly.Blocks['iot_system_run'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_RUN);
        this.appendValueInput("PATH")
            .setCheck(null)
            .appendField(Blockly.Msg.system_code_path);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(32);
        this.setTooltip(Blockly.Msg.Iot_System_Run_TOOLTIP);
        this.setHelpUrl("");
    }
};

Blockly.Blocks['iot_system_create_file'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_CREATE_FILE);
        this.appendValueInput("filename")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_CREATE_F);
        this.appendValueInput("PATH")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_CREATE_F_1);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(32);
        this.setTooltip(Blockly.Msg.Iot_System_Create_File_TOOLTIP);
        this.setHelpUrl("");
    }
};
Blockly.Blocks['iot_system_open_file'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_OPEN_FILE);
        this.appendValueInput("filename")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_WRITE_F);
        this.appendValueInput("PATH")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_CREATE_F_1);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(32);
        this.setHelpUrl("");
        this.setTooltip(Blockly.Msg.Iot_System_Open_File_TOOLTIP);
    }
};
Blockly.Blocks['iot_system_write_file'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_WRITE_FILE);
        this.appendValueInput("WPATH")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_WRITE_W);
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_WRITE_S)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.SYSTEM_WRITE_S_N, "newline"],
                [Blockly.Msg.SYSTEM_WRITE_S_C, "comma"],
                [Blockly.Msg.SYSTEM_WRITE_S_S, "space"],
                [Blockly.Msg.SYSTEM_WRITE_S_SE, "semicolon"]
            ]), "separator");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(32);
        this.setHelpUrl("");
        var thisBlock = this;
        this.setTooltip(function () {
            var mode = thisBlock.getFieldValue('separator');
            var TOOLTIPS = {
                'newline': Blockly.Msg.Iot_System_Write_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_N),
                'comma': Blockly.Msg.Iot_System_Write_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_C),
                'space': Blockly.Msg.Iot_System_Write_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_S),
                'semicolon': Blockly.Msg.Iot_System_Write_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_SE)
            };
            return TOOLTIPS[mode];
        });
    }
};

Blockly.Blocks['iot_system_close_file'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_CLOSE_FILE);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(32);
        this.setHelpUrl("");
        this.setTooltip(Blockly.Msg.SYSTEM_CLOSE_FILE);
    }
};
Blockly.Blocks['iot_system_delete_file'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.iot_system_delete);
        this.appendValueInput("PATH")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_CREATE_F_1);
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(32);
        this.setTooltip(Blockly.Msg.iot_system_delete_file_TOOLTIP);
        this.setHelpUrl("");
    }
};

Blockly.Blocks['iot_system_input_file'] = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_INPUT_FILE);
        this.appendValueInput("filename")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_WRITE_F);
        this.appendValueInput("PATH")
            .setCheck(null)
            .appendField(Blockly.Msg.SYSTEM_CREATE_F_1);
        this.appendDummyInput()
            .appendField(Blockly.Msg.SYSTEM_WRITE_S)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.SYSTEM_WRITE_S_N, "newline"],
                [Blockly.Msg.SYSTEM_WRITE_S_C, "comma"],
                [Blockly.Msg.SYSTEM_WRITE_S_S, "space"],
                [Blockly.Msg.SYSTEM_WRITE_S_SE, "semicolon"]
            ]), "separator");
        this.setInputsInline(false);
        this.setOutput(true, null);
        // this.setPreviousStatement(true, null);
        // this.setNextStatement(true, null);
        this.setColour(32);
        // this.setTooltip("");
        this.setHelpUrl("");
        var thisBlock = this;
        this.setTooltip(function () {
            var mode = thisBlock.getFieldValue('separator');
            var TOOLTIPS = {
                'newline': Blockly.Msg.Iot_System_Input_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_N),
                'comma': Blockly.Msg.Iot_System_Input_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_C),
                'space': Blockly.Msg.Iot_System_Input_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_S),
                'semicolon': Blockly.Msg.Iot_System_Input_File_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_SE)
            };
            return TOOLTIPS[mode];
        });
    }
};



export default Blockly;