@using TIAMWebApp.Shared.Application.Models.PageModels;
@using TIAMWebApp.Shared.Application.Models;
@using TIAMWebApp.Shared.Application.Interfaces;
@inject ISessionService sessionService;

<EditForm Model="@auctionBidModel" OnValidSubmit="GoToNextStep">
            <DataAnnotationsValidator />
    
  <h3>Step 1</h3>
    <div class="form-field d-flex align-items-center">
        

        <DxMaskedInput @bind-Value="@Email"
        Id="Email"
               CssClass="cw-320"                          
               Mask="@EmailMask"
               MaskMode="MaskMode.RegEx">
    <DxRegExMaskProperties MaskAutoCompleteMode="@((MaskAutoCompleteMode)AutoCompleteMode)"
                           Placeholder="Placeholder"
                           PlaceholdersVisible="PlaceholderVisible" />
                           </DxMaskedInput>
        
        
    </div>
    <ValidationMessage For="@(() => auctionBidModel.Email)" />
    
    <button class="btn btn-primary mt-3" type="submit">
        <span class="@spinnerClass"></span>
        Next
        </button>
    
</EditForm>



@code {
    [Parameter]
    public AuctionBidModel? auctionBidModel { get; set; }

    public string Email { get; set; } = "test@test.com";

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

    [Parameter]
    public EventCallback<AuctionBidModel> auctionBidModelChanged { get; set; }

    IEnumerable<char> PredefinedPlaceholders { get; set; } = new List<char>() { '_', '#' };

    string EmailMask { get; set; } = @"(\w|[.-])+@(\w|-)+\.(\w|-){2,4}";
    MaskAutoCompleteMode AutoCompleteMode { get; set; } = MaskAutoCompleteMode.Strong;
    char Placeholder { get; set; } = '_';
    bool PlaceholderVisible { get; set; } = false;

    private string spinnerClass = "";

    private async Task GoToNextStep()
    {
        spinnerClass = "spinner-border spinner-border-sm";
        await Task.Delay(500);
        auctionBidModel.Email = Email;
        spinnerClass = "";                
        await auctionBidModelChanged.InvokeAsync(auctionBidModel);
        await onNext.InvokeAsync();
    }

    protected override async Task OnInitializedAsync()
    {
        Email = sessionService.User.DisplayName;
        await base.OnInitializedAsync();
    }

}