class_name QuickSlots
extends Node


var _items: Array[String] = ["001", "002", "003", "004"]
var _selected_item: int = 0


func _init() -> void:
	InventoryManager.next_quick_slot.connect(select_next_item.bind())
	InventoryManager.previous_quick_slot.connect(select_previous_item.bind())
	InventoryManager.select_quick_slot.connect(select_item_index.bind())

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("quickslot0"):
		_selected_item = 0
	if event.is_action_pressed("quickslot1"):
		_selected_item = 1
	if event.is_action_pressed("quickslot2"):
		_selected_item = 2
	if event.is_action_pressed("quickslot3"):
		_selected_item = 3
	if event.is_action_pressed("quickslot_next"):
		select_next_item()
	if event.is_action_pressed("quickslot_previous"):
		select_previous_item()


func get_quickslot_index() -> int:
	return _selected_item

func get_selected_item() -> String:
	return _items[_selected_item]

func select_item_index(slot_index: int) -> void:
	_selected_item = slot_index
	InventoryManager.quick_slot_item_changed.emit(get_selected_item())

func select_previous_item() -> void:
	_selected_item = clampi(_selected_item - 1, 0, _items.size() - 1)
	InventoryManager.quick_slot_item_changed.emit(get_selected_item())

func select_next_item() -> void:
	_selected_item = clampi(_selected_item + 1, 0, _items.size() - 1)
	InventoryManager.quick_slot_item_changed.emit(get_selected_item())