using Connected.Models;
using Microsoft.AspNetCore.Components;

namespace Connected.Components;
public partial class InputText: InputBase
{
    [Parameter]
    public int NumOfRows
    {
		get
        {
            return _numberOfLines;
        }
        set
        {
            if (value < 1)
            {
                _numberOfLines = 1;
            }
            else
            {
                _numberOfLines = value;
            }
        }
    }
    private int _numberOfLines = 1;


	[Parameter]
   public string Value { get; set; }


    [Parameter]
    public EventCallback<string> ValueChanged { get; set; }

    private async Task ChangeValueAsync(ChangeEventArgs args)
    {
        await ValueChanged.InvokeAsync(args.Value.ToString());
		  StateHasChanged();
    }

	private async Task Clear()
	{
		await ValueChanged.InvokeAsync(string.Empty);
		StateHasChanged();

	}

	protected override async Task OnParametersSetAsync()
    {
		if (base.InputAttributes is null) base.InputAttributes = new();
		if (base.Required)
		{
			if (base.InputAttributes.ContainsKey("required")) base.InputAttributes.Add("required", true);
		}
		await base.OnInitializedAsync();
    }

}