var scriptName = "BlackBar";
var scriptVersion = 1.0;
var scriptAuthor = "scorpion3013";


// Part of https://github.com/CCBlueX/LiquidBounce-ScriptAPI/tree/master/lib
script.import("lib/glFunctions.js");
script.import("lib/systemFunctions.js")

var r,g,b,rainbowspeed;
var thicc
var borderColor
var borderOpacity
var borderColorComplete = '0x' + borderOpacity + borderColor;
var rainbowBoolean
function BlackHotBar() {

    this.getName = function () {
        return "BlackHotBar";
    };

    this.getDescription = function () {
        return "Renders a backhotbar";
    };

    this.getCategory = function () {
        return "Misc";
    };
    var c
    this.onEnable = function () {
       borderOpacity = 'FF';
       borderColor = 'f7f7f7';
       c = 0;
       thicc = 2;
       rainbowspeed = 40 / 500;
    }

    this.onUpdate = function () {
        if (mc.ingameGUI.getChatGUI().getChatOpen() == false) {

            if (rainbowBoolean) {
                if (44 > c) {
                    r = parseInt((Math.sin(c + Math.PI) + 1) * 127.5);
                    g = parseInt((Math.sin(c + (Math.PI / 2)) + 1) * 127.5);
                    b = parseInt(((Math.sin(c) + 1) * 127.5));
                    c = c + rainbowspeed;
                    borderColor = ('0' + r.toString(16)).slice(-2)  + ('0' + g.toString(16)).slice(-2)  + ('0' + b.toString(16)).slice(-2)
                } else {
                    c = 0;
                }
            }
        }
    }

    this.onRender2D = function () {
        if (mc.ingameGUI.getChatGUI().getChatOpen() == false) {

            
            
            


            var mcHeight = getScaledHeight();
            var mcWidth = getScaledWidth();
            var mcPOSX = parseInt(mc.thePlayer.posX);
            var mcPOSY = parseInt(mc.thePlayer.posY);
            var mcPOSZ = parseInt(mc.thePlayer.posZ);
            borderColorComplete = '0x' + borderOpacity + borderColor;
            drawRect(thicc, mcHeight - 23 + thicc, mcWidth - thicc, mcHeight - thicc, 0x7E000000); //innerRect
            
            drawRect(thicc, mcHeight - thicc, mcWidth - thicc, mcHeight, borderColorComplete); //bottomRect
            drawRect(thicc, mcHeight - 23, mcWidth - thicc, mcHeight - 23 + thicc, borderColorComplete); //topRect
            
            drawRect(0, mcHeight - 23, thicc, mcHeight, borderColorComplete); //leftRect
            drawRect(mcWidth - thicc, mcHeight - 23, mcWidth, mcHeight, borderColorComplete); //rightRect


            mc.fontRendererObj.drawStringWithShadow('PosX: ' + mcPOSX + '  PosY: ' + mcPOSY + '  PosZ: ' + mcPOSZ, 4, mcHeight - 11, 0xf7f7f7);
            mc.fontRendererObj.drawStringWithShadow('Name: ' + mc.getSession().getUsername() + '  ' , 4, mcHeight - 20, 0xf7f7f7);
            var d = new Date();
            var month = d.getMonth() + 1

            var datestringEU = 'Date: ' + ('0' + d.getDate()).slice(-2) + '/' + ('0' + month).slice(-2) + '/' + d.getFullYear();
            var datestringUS = 'Date: ' + ('0' + d.getMonth()).slice(-2) + '/' + ('0' + month).slice(-2) + '/' + d.getFullYear();

            mc.fontRendererObj.drawStringWithShadow(datestringEU, mcWidth - 90  , mcHeight - 11, 0xf7f7f7);
            var timestring= 'Time: ' + ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2);
            mc.fontRendererObj.drawStringWithShadow(timestring, mcWidth - 90  , mcHeight - 20, 0xf7f7f7);
            
        }

    }


}



function HotbarCommand() {
    this.getName = function() {
        return "hotbarCommand";
    }
    this.getAliases = function() {
        return ["blackhotbar", "bhb"];
    }
    this.execute = function(string) {
        if (string.length > 1) {
            switch (string[1]) {
                case 'borderopacity':
                case 'bo':
                    if (string.length > 2) {
                        var int = parseInt(string[2]);
                        borderOpacity = ('0' + int.toString(16)).slice(-2);
                        chat.print(('Changed borderopacity'));
                    } else {
                        chat.print('Missing argument, choose a number between 0-255');
                    }
                    
                    break;
                case 'bordercolor':
                case 'bc':
                    if (string.length > 2) {
                        var hex = string[2];
                        chat.print(hex)
                        borderColor = hex.toString(16)
                        chat.print(('Changed bordercolor, if the border is transparent -> you did something wrong'));
                        borderColorComplete = '0x' + borderOpacity + borderColor;
                    } else {
                        chat.print('Missing argument, choose a hexcolor from https://www.google.com/search?q=hexcolorpicker');
                        chat.print('example: 0549af')
                    }
                    break;

                case 'rainbow':
                     if (string.length > 2 ) {
                        if (string[2] == 'true') {
                            rainbowBoolean = true;
                        } else if (string[2] == 'false') {
                            rainbowBoolean = false;
                        } else {
                            chat.print('Wrong aregument, choose true or false')
                        }

                    } else {
                        chat.print('Missing argument, true or false');
                    }
                    break;
                case 'rainbowspeed':
                    if (string.length > 2 ) {
                        if ( 100 >= parseInt(string[2]) > 0) {
                            rainbowspeed = parseInt(string[2]) / 500;
                        } else {
                            chat.print('Wrong argument, need to be a number between 0 - 100');
                        }
                    } else {
                        chat.print('Missing argument, 0- 100');
                    }
                    break;

                case 'thiccness':
                case 'thicc':
                    if (string.length > 2 ) {
                        if (parseInt(string[2]) > 1) {
                            thicc = parseInt(string[2]);
                        } else {
                            chat.print('Wrong aregument, a number that is bigger or equal to 2');
                        }

                    } else {
                        chat.print('Missing argument, number');
                    }
                    break;
                case 'credits':
                    chat.print('§6Made by scorpion3013 ');
                    break;
                case 'help':
                default:
                    chat.print('borderopacity/bo, bordercolor/bc, rainbow, rainbowspeed,thiccness');
            }
        } else {
            chat.print('use .bhb help');
        }

        //tester = string[1];
    }
}




//Modules and commands register
var blackHotBar = new BlackHotBar();
var blackHotBarClient;

var hotbarCommand = new HotbarCommand();
var hotbarCommandClient;

function onLoad() {

};

function onEnable() {
    blackHotBarClient = moduleManager.registerModule(blackHotBar);
    hotbarCommandClient = commandManager.registerCommand(hotbarCommand);
};

function onDisable() {
    moduleManager.unregisterModule(blackHotBarClient);
    commandManager.unregisterCommand(hotbarCommandClient);
};
