package ru.dbotthepony.mc.otm.client.screen.panels.slot

import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot
import ru.dbotthepony.mc.otm.container.ItemFilterSlotPacket
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel

open class FilterSlotPanel<out S : MatteryScreen<*>> @JvmOverloads constructor(
	screen: S,
	parent: EditablePanel<*>?,
	val slot: ItemFilterNetworkSlot,
	x: Float = 0f,
	y: Float = 0f,
	width: Float = SIZE,
	height: Float = SIZE
) : AbstractSlotPanel<S>(screen, parent, x, y, width, height) {
	override val itemStack: ItemStack get() {
		return slot.get()
	}

	override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
		if (!screen.menu.ply.isSpectator) {
			if (screen.menu.carried.isEmpty) {
				MenuNetworkChannel.sendToServer(ItemFilterSlotPacket(slot.networkID, ItemStack.EMPTY))
			} else {
				MenuNetworkChannel.sendToServer(ItemFilterSlotPacket(slot.networkID, screen.menu.carried))
			}
		}

		return true
	}
}
