extends Node2D

func _process(_delta: float) -> void:
	$Points.text = str(State.points)

func _on_button_button_down():
	State.blower_up = true
	$PointsTimer.paused = false
	$AnimationPlayer.current_animation = "blower_up"

func _on_button_button_up():
	State.blower_up = false
	$PointsTimer.paused = true
	$AnimationPlayer.current_animation = "blower_down"

func _on_points_timer_timeout():
	if State.blowing && State.points > 0:
		State.points -= 1

	if State.points == 0:
		$Button.button_pressed = false
		$Button.release_focus()
		State.blower_up = false
		State.blowing = false
		$AnimationPlayer.current_animation = "blower_down"

		$PointsTimer.paused = true
		$Microtransaction.visible = true
		$Backdrop.visible = true


func _on_microtransaction_canceled() -> void:
	State.points = 80
	$PointsTimer.paused = false
	$Microtransaction.visible = false
	$Backdrop.visible = false


func _on_microtransaction_confirmed() -> void:
	State.points = 40
	$PointsTimer.paused = false
	$Microtransaction.visible = false
	$Backdrop.visible = false


func _on_button_mouse_exited() -> void:
	$Button.button_pressed = false
