using Connected.Enums;
using Connected.Utilities;
using Microsoft.AspNetCore.Components;
using static Connected.Colors;

namespace Connected.Components;
public partial class Link
{
	/// <summary>
	/// URL of the link
	/// Options: Any valid URL adress
	/// Default: string.Empty
	/// </summary>
	[Parameter, EditorRequired]
	public string Url { get; set; } = string.Empty;

	/// <summary>
	/// Text shown for the link. If this is not provided URL is used
	/// Options: Any valid string
	/// Default: string.Empty
	/// </summary>
	[Parameter]
	public string Text { get; set; } = string.Empty;

	/// <summary>
	/// Target where the link shall open
	/// Options: Target.[Self,Parent,Top,Blank]
	/// Default: Target.Self
	/// </summary>
	[Parameter]
	public Target Target { get; set; } = Target.Self;

	private string _target
	{
		get
		{
			return Helper.GetEnumDescription<Target>(Target);
		}
	}

	/// <summary>
	/// Class name or multiple classes separated by space
	/// Options: Any valid class name or names separated by space
	/// Default: string.Empty
	/// </summary>
	[Parameter]
	public string Class { get; set; } = string.Empty;

	private string LinkClassList
	{
		get
		{
			return new CssBuilder("btn")
				 .AddClass("btn-sm")
				 .AddClass("btn-link-core")
				 .AddClass(Class)
				 .Build();
		}
	}

	/// <summary>
	/// Style string for the link
	/// Options: Any valid CSS style
	/// Default: string.Empty
	/// </summary>
	[Parameter]
	public string Style { get; set; } = string.Empty;

	private string LinkStyleList
	{
		get
		{
			return new StyleBuilder()
				 .AddStyle(Style)
				 .Build();
		}
	}

	protected override async Task OnInitializedAsync()
	{
		//if Text parameter is not provided we set it to match URL
		if (string.IsNullOrEmpty(Text))
			Text = Url;

		await base.OnInitializedAsync();
	}
}


