extends BaseState

signal PlayerBeganDrawingBow

@export var strafing_speed := 35
@export var body: CharacterBody2D

var _used_item_action: String
var _animation_finished := false
var _movement_componenent: MovementComponent

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


func Enter(extra_parameters: Dictionary) -> void:
	_animation_finished = false
	_used_item_action = extra_parameters.action_name
	_movement_componenent = ComponentUtils.GetMovementComponent(body)
	PlayerBeganDrawingBow.emit()


func Update(_delta: float) -> void:
	if !_animation_finished:
		return
	
	if !Input.is_action_pressed(_used_item_action):
		state_machine.QueueStateChange(PlayerStateMachine.States.FIRING_ARROW)
		return
	
	var movement_vector := _movement_componenent.movement_vector
	if movement_vector != Vector2.ZERO:
		body.velocity = movement_vector * strafing_speed
		body.move_and_slide()


func OnDrawingBowAnimationFinished() -> void:
	_animation_finished = true
