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

<EditForm Model="@auctionBidModel" OnValidSubmit="GoToNextStep">
    <DataAnnotationsValidator />

    <h3>Step 1</h3>
    <div class="form-field d-flex align-items-center">


        
        <button class="btn btn-primary mt-3" type="submit">
            <span class="@spinnerClass"></span>
            Licitálok!
        </button>


    </div>
    


</EditForm>


@code {

    [Parameter]
    public AuctionBidModel auctionBidModel { get; set; }
    [Parameter]
    public int TargetProductId { get; set; }
    [Parameter]
    public EventCallback<string> onNext { get; set; }
    [Parameter]
    public EventCallback<AuctionBidModel> auctionBidModelChanged { get; set; }

    public Guid UserId { get; set; }

    private string spinnerClass = "";

    private async Task GoToNextStep()
    {
        spinnerClass = "spinner-border spinner-border-sm";
        await Task.Delay(500);
        auctionBidModel.Id = Guid.NewGuid();
        auctionBidModel.OwnerId = sessionService.User.UserId;
        auctionBidModel.TargetProductId = TargetProductId;
        spinnerClass = "";  
        await auctionBidModelChanged.InvokeAsync(auctionBidModel);
        await onNext.InvokeAsync();
    }

}