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

namespace Connected.Components;

public abstract class UIComponent : ComponentBase
{
	/// <summary>
	/// Use Tag to attach any user data object to the component for your convenience.
	/// </summary>
	[Parameter]
	public object? Tag { get; set; }

	/// <summary>
	/// UserAttributes carries all attributes you add to the component that don't match any of its parameters.
	/// They will be splatted onto the underlying HTML tag.
	/// </summary>
	[Parameter(CaptureUnmatchedValues = true)]
	public Dictionary<string, object> CustomAttributes { get; set; } = new();

	/// <summary>
	/// If the UserAttributes contain an ID make it accessible for WCAG labelling of input fields
	/// </summary>
	public string FieldId => CustomAttributes.TryGetValue("id", out var id) ? id?.ToString() ?? string.Empty : $"input-{Guid.NewGuid()}";

	[Obsolete]
	public string AdditionalClassList => string.Empty;
}
