import * as Blockly from 'blockly';
import { pythonGenerator } from 'blockly/python';

Blockly.Python = pythonGenerator || { Msg: Object.create(null) };

const color = '#60c1bb';

Blockly.Blocks['ai_camera_init'] = {
    init: function () {
        this.appendDummyInput()
            .appendField('摄像头初始化');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(color);
        this.setTooltip('初始化摄像头');
        this.setHelpUrl('');
    }
};

Blockly.Python['ai_camera_init'] = function (block) {
    var code = 'camera.init()\n';
    return code;
};

Blockly.Blocks['ai_camera_windows'] = {
    init: function () {
        this.appendDummyInput()
            .appendField('获取相机图像');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(color);
        this.setTooltip('获取相机图像');
        this.setHelpUrl('');
    }
};

Blockly.Python['ai_camera_windows'] = function (block) {
    var code = 'camera.windows()\n';
    return code;
};

Blockly.Blocks['ai_camera_image_property_change'] = {
    init: function () {
        this.appendDummyInput()
            .appendField('摄像头窗口');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(color);
        this.setTooltip('打开摄像头窗口');
        this.setHelpUrl('');
    }
};

Blockly.Python['ai_camera_image_property_change'] = function (block) {
    var code = 'display.show(image)\n';
    return code;
}

Blockly.Blocks['ai_camera_snapshot'] = { 
    init: function () {
        this.appendDummyInput()
            .appendField('摄像头拍照');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(color);
        this.setTooltip('拍摄一张照片');
        this.setHelpUrl('');
    }
};

Blockly.Python['ai_camera_snapshot'] = function (block) {
    var code = 'camera.snapshot()\n';
    return code;
};

Blockly.Blocks['v831_camera_graph_transmission'] = {
    init: function () {
        this.appendDummyInput()
            .appendField('V831摄像头图像传输');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(color);
        this.setTooltip('V831摄像头图像传输');
        this.setHelpUrl('');
    }
};

Blockly.Python['v831_camera_graph_transmission'] = function (block) {
    var code = 'V831摄像头图像传输()\n';
    return code;
};

export default Blockly;
