'use strict';

goog.provide('Blockly.Blocks.color');
goog.require('Blockly.Blocks');
goog.require('Blockly.Types');

Blockly.Blocks.color.HUE = 330;

Blockly.Blocks['color_analyzer_setup'] = {
    init: function() {
        this.appendDummyInput()
            // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_colorAnalyzer.png", 140, 40, "0"));
            .appendField(new Blockly.FieldImage("./../blockly/media/main-color.png", 50, 40, "0"));
        this.appendDummyInput()
            .appendField(Blockly.Msg.COLORANALYZER_SETUP);
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip('');
        this.setHelpUrl('');
    }
};

Blockly.Blocks['set_color'] = {
    init: function() {
        this.appendDummyInput()
            .appendField(Blockly.Msg.COLOR)
            .appendField(new Blockly.FieldColour("#ff0000"), "COLOR");
        this.setOutput(true, "String");
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

Blockly.Blocks['read_r'] = {
    init: function() {
        this.appendDummyInput()
            .appendField(Blockly.Msg.READ_R);
        this.setOutput(true, Blockly.Types.NUMBER.output);
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    },
    getBlockType: function() {
        return Blockly.Types.NUMBER;
    }
}

Blockly.Blocks['read_g'] = {
    init: function() {
        this.appendDummyInput()
            .appendField(Blockly.Msg.READ_G);
        this.setOutput(true, Blockly.Types.NUMBER.output);
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    },
    getBlockType: function() {
        return Blockly.Types.NUMBER;
    }
}

Blockly.Blocks['read_b'] = {
    init: function() {
        this.appendDummyInput()
            .appendField(Blockly.Msg.READ_B);
        this.setOutput(true, Blockly.Types.NUMBER.output);
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    },
    getBlockType: function() {
        return Blockly.Types.NUMBER;
    }
}

Blockly.Blocks['set_colorRGB'] = {
    init: function() {
        this.appendDummyInput()
            .appendField(Blockly.Msg.COLOR);
        this.appendValueInput("RED_VAL")
            .setCheck(null)
            .appendField(Blockly.Msg.RED);
        this.appendValueInput("GREEN_VAL")
            .setCheck(null)
            .appendField(Blockly.Msg.GREEN);
        this.appendValueInput("BLUE_VAL")
            .setCheck(null)
            .appendField(Blockly.Msg.BLUE);
        this.setInputsInline(true);
        this.setOutput(true, "String");
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip("");
        this.setHelpUrl("http://help.cocorobo.cn/#/cocomod/color-analyzer?id=rgb-%E5%8F%96%E8%89%B2%E5%99%A8");
    }
}

Blockly.Blocks['isColorRGB'] = {
    init: function() {
        this.appendDummyInput()
            .appendField(Blockly.Msg.ISCOLOR)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.RED, "r"],
                [Blockly.Msg.GREEN, "g"],
                [Blockly.Msg.BLUE, "b"]
            ]), "COLOR");
        this.setOutput(true, "Boolean");
        this.setColour(Blockly.Blocks.color.HUE);
        this.setTooltip("");
        this.setHelpUrl("http://help.cocorobo.cn/#/cocomod/color-analyzer?id=rgb-%E5%8F%96%E8%89%B2%E5%99%A8");
    }
}