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

namespace Connected.Components;
public partial class GridRow : ComponentBase
{

	[CascadingParameter]
	public Grid Parent { get; set; }

	public List<GridRowContent> Children { get; set; }

	[Parameter]
	public RenderFragment? ChildContent { get; set; }

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

	private void ToggleNav()
	{
		CollapsedItemShown = !CollapsedItemShown;
	}

	[Parameter]
	public string Class { get; set; } = string.Empty;

	[Parameter]
	public GridRowTemplate? Template { get; set; } = null;

	private string GridRowClass
	{
		get
		{
			return new CssBuilder("data-grid-row-content")
				.AddClass("show",CollapsedItemShown)
				.AddClass(Class)
				.Build();
		}
	}

	[Parameter]
	public EventCallback<ChangeEventArgs> SwitchButtonChangeEvent { get; set; }

	private async Task SwitchButtonChange(ChangeEventArgs args)
	{
		await SwitchButtonChangeEvent.InvokeAsync(args);
	}

	private string SwitchButtonId = Guid.NewGuid().ToString();

	protected override async Task OnInitializedAsync()
	{
		if (Parent.Rows is null) Parent.Rows = new();
		Parent.Rows.Add(this);
		await base.OnInitializedAsync();
	}

}