var scriptName = "HideGUI";
var scriptAuthor = "Nvaros";
var scriptVersion = 1.0;

var LiquidBounce = Java.type("net.ccbluex.liquidbounce.LiquidBounce");
var ModuleElement = Java.type("net.ccbluex.liquidbounce.ui.client.clickgui.elements.ModuleElement");
var PositionedSoundRecord = Java.type("net.minecraft.client.audio.PositionedSoundRecord");
var ResourceLocation = Java.type("net.minecraft.util.ResourceLocation");

var HiddenModules = [];
var HiddenModuleInfo = [];

function ClickGUIHide() {

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

    this.getAliases = function() {
        return ["hgui"];
    };

    this.execute = function(args) {
   
		if (args.length >= 2) {
			switch(args[1].toLowerCase()) {
				
			case "hide":
				if (args.length >= 3) {
					var newHiddenModule = args[2].toLowerCase();
					var length = HiddenModules.length;
					var LBPanels = LiquidBounce.clickGui.panels;
					
					for (var i in LBPanels) {
						var panelElements = LBPanels.get(i).getElements();
						if (panelElements.get(0) instanceof ModuleElement) {
							for (var j in panelElements) {
								if (panelElements.get(j).getModule().getName().toLowerCase() == newHiddenModule) {
									chat.print("Hid module " + newHiddenModule + " from ClickGUI!");
									HiddenModules.push(newHiddenModule);
									HiddenModuleInfo.push([i, j, panelElements.get(j).getModule()]);
									panelElements.remove(j);
									break;
								};
							}
						} 
					};
					
					if (HiddenModules.length == length) {
						chat.print("This module has either been hidden or does not exist!");
					};
				
				} else {
					chat.print("�cSyntax: .hidegui hide <module>");
				}
			break;
			
			case "unhide":
				if (args.length >= 3) {
					var unhiddenModule = args[2].toLowerCase();
					var panels = LiquidBounce.clickGui.panels;
					var index = HiddenModules.indexOf(unhiddenModule);
					
					if (index < 0) {
						chat.print("This module is not hidden in the ClickGUI!");
					} else {
						var Module = HiddenModuleInfo[index][2];
						var ModuleButton = new (Java.extend(ModuleElement))(Module) {
							mouseClicked: function(mouseX, mouseY, mouseButton) {
								if (mouseButton == 0 && ModuleButton.isHovering(mouseX, mouseY) && ModuleButton.isVisible()) {
									Module.toggle();
									mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1));
								}
								
								if (mouseButton == 1 && ModuleButton.isHovering(mouseX, mouseY) && ModuleButton.isVisible()) {
									ModuleButton.showSettings = !ModuleButton.showSettings;
									mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1));
								}
							}		
						}
						chat.print("Unhid module " + unhiddenModule + " from ClickGUI!");
						panels.get(HiddenModuleInfo[index][0]).getElements().add(HiddenModuleInfo[index][1], ModuleButton);
						HiddenModuleInfo.splice(index, 1);
						HiddenModules.splice(index, 1);
					};

				} else {
					chat.print("Syntax: .hidegui unhide <module>");
				}
			break;
			
			case "list":
				if (HiddenModules.length == 0) {
					chat.print("You didn't hide any module from the ClickGUI!");
				} else {
					chat.print("Hidden modules (ClickGUI!):");
					chat.print(HiddenModules);
				}
				
			break;
				
			default:
				chat.print("Invalid syntax! Usage: .hidegui <hide/unhide> module");
			break;
			}
		
		} else {
			chat.print("Invalid syntax! Usage: .hidegui <hide/unhide> module");
		}
	
	
	};
	
}



var commands = [
	new ClickGUIHide()
]

function onEnable() {    
	commandManager.registerCommand(commands[0]);	
};


function onDisable() {
	commandManager.unregisterCommand(commands[0]);   
}