using Connected.Utilities;
using Microsoft.AspNetCore.Components;

namespace Connected.Components;
public partial class Alert
{
	[Parameter]
	public bool ShowGlyph { get; set; } = true;
	private string Glyph { get; set; } = string.Empty;

	[Parameter]
	public bool ShowCloseButton { get; set; } = false;

	private string CloseButton { get; set; } = Icons.Material.Outlined.Close;
	
	[Parameter]
	public bool Closed { get; set; } = false;

	[Parameter, EditorRequired]
	public string Text { get; set; } = string.Empty;

	[Parameter]
	public Severity Severity { get; set;} = Severity.Normal;

	protected override async Task OnParametersSetAsync()
	{
		switch (Severity)
		{
			case Severity.Normal:
				{
					Glyph = Icons.Material.Outlined.EventNote;
					break;
				}
			case Severity.Info:
				{
					Glyph = Icons.Material.Outlined.Info;
					break;
				}
			case Severity.Success:
				{
					Glyph = Icons.Material.Outlined.Check;
					break;
				}
			case Severity.Warning:
				{
					Glyph = Icons.Material.Outlined.ReportProblem;
					break;
				}
			case Severity.Error:
				{
					Glyph = Icons.Material.Filled.ErrorOutline;
					break;
				}
			default:
				{
					Glyph = Icons.Material.Outlined.EventNote;
					break;
				}
		}
		await base.OnParametersSetAsync();
	}

	/// <summary>
	/// Child content of the component.
	/// </summary>
	[Parameter]
	public RenderFragment? ChildContent { get; set; }

	private void OnCloseClick()
	{
		Closed = true;
		StateHasChanged();
	}

	[Parameter]
	public string ClassList { get; set; } = string.Empty;
	/// <summary>
	/// Contains the default container classlist and the user defined classes.
	/// </summary>
	private string CompiledClassList
	{
		get
		{
			return new CssBuilder("alert")
				.AddClass($"alert-text-{Severity}")
				.AddClass(ClassList)
				.Build();
		}
	}
}
