package client.gui.element;

import client.Client;
import client.renderer.Drawing;
import common.inventory.Slot;
import common.util.Util;

public class InventoryButton extends Element {
	private final boolean bordered;
	private final Slot slot;
	private final String texture;
	
	public InventoryButton(int x, int y, int w, int h, boolean bordered, Slot slot) {
		super(x, y, w, h, null);
		this.bordered = bordered;
		this.texture = slot == null || slot.getTexture() == null ? null : "textures/items/icon_" + slot.getTexture() + ".png";
		this.slot = this.texture == null ? null : slot;
	}
	
	protected void drawBackground() {
		drawButton(this.gm, this.pos_x, this.pos_y, this.size_x, this.size_y, this.bordered);
		if(this.texture != null && !this.slot.getHasStack()) {
			int scale = this.bordered ? 2 : 1;
			Drawing.drawTexturedRect(this.gm, this.texture, 16 * scale, 16 * scale, this.pos_x + scale, this.pos_y + scale, 0, 0, this.size_x - scale * 2, this.size_y - scale * 2);
		}
	}
	
	protected void drawForeground(int x1, int y1, int x2, int y2) {
	}
	
	public static void drawButton(Client gm, int x, int y, int w, int h, boolean border) {
		if(border)
			Drawing.drawDoubleRect(x, y, w, h, Util.mixColor(gm.style.fill_top, gm.style.fill_btm), gm.style.brdr_top, gm.style.brdr_btm);
		else
			Drawing.drawRect(x, y, w, h, Util.mixColor(gm.style.fill_top, gm.style.fill_btm), gm.style.brdr_top, gm.style.brdr_btm);
	}
}
