#include "JavaInventory.h"
#include "Client.h"

#include "Utils/FileUtils.h"

auto JavaInventory::onContainerScreenSlotHovered(ContainerScreenController* _this, std::string collectionName, int64_t slot) -> void {
	lastcollectionName = collectionName;
	lastslot = static_cast<int>(slot);
}

auto JavaInventory::onContainerScreenTick(ContainerScreenController* _this) -> void {
	if (Client::screenName != _("inventory_screen")) return;
	if (lastslot == -1) return;

	if (swap) {
		_this->handleTakeAll(lastcollectionName, lastslot);
		_this->handlePlaceAll(_("hotbar_items"), moveslot - 1);
		_this->handlePlaceAll(lastcollectionName, lastslot);
		lastslot = -1;
		swap = false;
	}
}

auto JavaInventory::onKeyboard(int key, bool* held, bool* cancel) -> void {
	if (!held) return;

	if (key == Client::opthotbar1) {
		moveslot = 1;
		swap = true;
	}
	if (key == Client::opthotbar2) {
		moveslot = 2;
		swap = true;
	}
	if (key == Client::opthotbar3) {
		moveslot = 3;
		swap = true;
	}
	if (key == Client::opthotbar4) {
		moveslot = 4;
		swap = true;
	}
	if (key == Client::opthotbar5) {
		moveslot = 5;
		swap = true;
	}
	if (key == Client::opthotbar6) {
		moveslot = 6;
		swap = true;
	}
	if (key == Client::opthotbar7) {
		moveslot = 7;
		swap = true;
	}
	if (key == Client::opthotbar8) {
		moveslot = 8;
		swap = true;
	}
	if (key == Client::opthotbar9) {
		moveslot = 9;
		swap = true;
	}
}
