@page "/login"
@rendermode InteractiveServer
@using System.ComponentModel.DataAnnotations
@using DevExpress.Blazor

<h3>Login</h3>


<EditForm Model="_model" OnValidSubmit="OnLogin">
    <ChildContent Context="formCtx">
        <DataAnnotationsValidator />

        <DxFormLayout>
            <DxFormLayoutItem Caption="Benutzername">
                <ChildContent Context="itemCtx">
                    <DxTextBox @bind-Text="_model.Benutzername" />
                </ChildContent>
            </DxFormLayoutItem>

            <DxFormLayoutItem Caption="Passwort">
                <ChildContent Context="itemCtx">
                    <DxTextBox @bind-Text="_model.Passwort" Password="true" />
                </ChildContent>
            </DxFormLayoutItem>

            <DxFormLayoutItem>
                <ChildContent Context="itemCtx">
                    <DxButton Text="Login"
                              SubmitFormOnClick="true"
                              RenderStyle="ButtonRenderStyle.Primary" />
                </ChildContent>
            </DxFormLayoutItem>
        </DxFormLayout>

        @if (!string.IsNullOrEmpty(_error))
        {
            <div style="color:red;margin-top:10px;">@_error</div>
        }

        @if (_success)
        {
            <div style="color:green;margin-top:10px;">Login erfolgreich!</div>
        }
    </ChildContent>
</EditForm>

@code {

    private LoginModel _model = new();
    private string? _error;
    private bool _success;

    private async Task OnLogin()
    {
        
    }



    private class LoginModel
    {
        [Required]
        public string? Benutzername { get; set; }

        [Required]
        public string? Passwort { get; set; }
    }
}
