extends BaseState
class_name PlayerIdleState

@export var movement_component: MovementComponent

signal PlayerBecameIdle

var _sit_queued := false
var _sit_queue_pos: Vector2
var _sit_queue_dir: Enums.Directions


func GetStateEnum() -> PlayerStateMachine.States:
	return PlayerStateMachine.States.IDLE


func Enter(_extra_parameters: Dictionary) -> void:
	PlayerBecameIdle.emit()


func Update(_delta: float) -> void:
	var item_a := Input.is_action_just_pressed("use_item_a")
	
	if item_a:
		state_machine.QueueStateChange(PlayerStateMachine.States.USING_ITEM_A, {})
		return
	
	if _sit_queued:
		state_machine.QueueStateChange(PlayerStateMachine.States.SITTING, {"pos": _sit_queue_pos, "dir": _sit_queue_dir})
		_sit_queued = false
		return
	
	if movement_component.movement_vector != Vector2.ZERO:
		state_machine.QueueStateChange(PlayerStateMachine.States.WALKING)


func OnSitOnFurnitureTriggered(sitting_position: Vector2, sitting_direction: Enums.Directions) -> void:
	if state_machine.GetCurrentStateEnum() != GetStateEnum():
		return
	
	_sit_queued = true
	_sit_queue_pos = sitting_position
	_sit_queue_dir = sitting_direction


func OnCutsceneStarted() -> void:
	state_machine.QueueStateChange(PlayerStateMachine.States.CUTSCENE)
