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

namespace Connected.Components;
public partial class GridRowContent : ComponentBase
{
	[CascadingParameter]
	public GridRow? Parent { get; set; }

	/// <summary>
	/// Text shown inside the button
	/// Options: any string variable
	/// Default: string.Empty
	/// </summary>
	[Parameter]
	public RenderFragment? ChildContent { get; set; }

	/// <summary>
	/// Disabled or enabled.
	/// Default: false
	/// </summary>
	[Parameter]
	public bool Collapsable { get; set; } = false;

	private string GeneratedRowContentClass
	{
		get
		{
			CssBuilder cssBuilder = new CssBuilder("row");

			cssBuilder.AddClass("collapsed", Collapsable);

			if (Parent is not null)
			{
				cssBuilder.AddClass("show", (Collapsable ? Parent.CollapsedItemShown : false));
			}

			return cssBuilder.Build();
		}
	}

	protected override async Task OnInitializedAsync()
	{

		if (Parent is not null)
		{
			if (Parent.Children is null) Parent.Children = new();
			Parent.Children.Add(this);
		}
		await base.OnInitializedAsync();
	}
}

