@using DxBlazorApplication2.Services;
@inject TodoService _todoService;

<EditForm Model="@NewItem" OnSubmit="@ItemAdded">
    <div style="display: flex; align-items: center; width: 400px;">
        <div style="margin-right: 10px">Text:</div>
        <InputText @bind-Value="NewItem.Text" class="form-control" style="margin-right: 10px" id="Item" />
        <input type="submit" class="btn btn-primary" style="margin-right: 10px" value="Hinzufügen" />
        <input type="reset" class="btn btn-secondary" value="Leeren" />
    </div>
</EditForm>

@code
{
    [Parameter]
    public required Action OnItemAdded { get; set; }

    private TodoItem NewItem = new TodoItem("");

    public void ItemAdded()
    {
        var newItem = new TodoItem(NewItem.Text);
        NewItem.Text = "";
        _todoService.AddItem(newItem);

        if (OnItemAdded != null)
            OnItemAdded();
    }
}
