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

namespace Connected.Components;

public partial class TextContent : UIComponent
{
	protected string Classname =>
	new CssBuilder("typography")
	  .AddClass($"typography-{Typo.ToDescription()}")
	  .AddClass($"{Color.ToDescription()}-text", Color != ThemeColor.Default && Color != ThemeColor.Inherit)
	  .AddClass("typography-gutterbottom", GutterBottom)
	  .AddClass($"typography-align-{ConvertAlign(Align).ToDescription()}", Align != Align.Inherit)
	  .AddClass("typography-display-inline", Inline)
	  .AddClass(AdditionalClassList)
	.Build();

	private Align ConvertAlign(Align align)
	{
		return align switch
		{
			Align.Start => RightToLeft ? Align.Right : Align.Left,
			Align.End => RightToLeft ? Align.Left : Align.Right,
			_ => align
		};
	}

	[CascadingParameter(Name = "RightToLeft")] public bool RightToLeft { get; set; }

	/// <summary>
	/// Applies the theme typography styles.
	/// </summary>
	[Parameter]
	[Category(CategoryTypes.Text.Appearance)]
	public Typo Typo { get; set; } = Typo.body1;

	/// <summary>
	/// Set the text-align on the component.
	/// </summary>
	[Parameter]
	[Category(CategoryTypes.Text.Appearance)]
	public Align Align { get; set; } = Align.Inherit;

	/// <summary>
	/// The color of the component. It supports the theme colors.
	/// </summary>
	[Parameter]
	[Category(CategoryTypes.Text.Appearance)]
	public ThemeColor Color { get; set; } = ThemeColor.Inherit;

	/// <summary>
	/// If true, the text will have a bottom margin.
	/// </summary>
	[Parameter]
	[Category(CategoryTypes.Text.Appearance)]
	public bool GutterBottom { get; set; } = false;

	/// <summary>
	/// Child content of component.
	/// </summary>
	[Parameter]
	[Category(CategoryTypes.Text.Behavior)]
	public RenderFragment ChildContent { get; set; }

	/// <summary>
	/// If true, Sets display inline
	/// </summary>
	[Parameter]
	[Category(CategoryTypes.Text.Appearance)]
	public bool Inline { get; set; }
}
