using Godot;
using System;

namespace Hellswipers.Game;

public partial class Arrow : Polygon2D {
	public enum Dirs { Right, Down, Left, Up }
	
	private static readonly Color NormalColor = Colors.White;
	private static readonly Color DoneColor = Colors.Khaki;
	private static readonly Color ErrorColor = Color.Color8(217, 70, 72);
	
	private Polygon2D _inner;
	private bool _done = false;
	public Dirs CurrentDir { private set; get; }

	public override void _Ready() {
		_inner = GetNode<Polygon2D>("Inner");
	}

	public void SetDir(Dirs dir) {
		CurrentDir = dir;
		Rotation = dir switch {
			Dirs.Right => 0,
			Dirs.Down => (float)(Math.PI / 2),
			Dirs.Left => (float)Math.PI,
			Dirs.Up => (float)(Math.PI * 3 / 2),
			_ => Rotation
		};
	}

	public void Done() {
		_done = true;
		_inner.Color = DoneColor;
	}

	public void Error() {
		var tween = CreateTween();
		tween.TweenProperty(_inner, "color", ErrorColor, 0.15);
		tween.TweenInterval(0.15);
		tween.TweenProperty(_inner, "color", NormalColor, 0.2);
		_done = false;
	}
}
