@page "/Accounts/Delete/{AccountId}"

@using Gremlin_BlazorServer.Data.EntityClasses;
@using Gremlin_BlazorServer.Services;

@inject AccountService accountService
@inject NavigationManager navigationManager

<h2>Delete Employee</h2>
<hr />
<h3>Are you sure want to delete this?</h3>
<form>
    <div class="row">
        <div class=" col-md-8">
            <div class="form-group">
                <label>AccountId:</label>
                <label>@account.AccountId</label>
            </div>
            <div class="form-group">
                <label>AccountName:</label>
                <label>@account.AccountName</label>
            </div>
            <div class="form-group">
                <label>Street:</label>
                <label>@account.Street</label>
            </div>
            <div class="form-group">
                <label>ZIP:</label>
                <label>@account.ZIP</label>
            </div>
            <div class="form-group">
                <label>City:</label>
                <label>@account.City</label>
            </div>
        </div>

    </div>
    <div class="row">
        <div class="col-md-4">
            <div class="form-group">
                <input type="button" class="btn btn-danger" @onclick="@DeleteAccount" value="Delete" />
                <input type="button" class="btn btn-primary" @onclick="@Cancel" value="Cancel" />
            </div>
        </div>
    </div>
</form>

@code {
    [Parameter]
    public string AccountId { get; set; } = default!;
    Account account = new Account();

    protected override async Task OnInitializedAsync()
    {
        account = await Task.Run(() => accountService.GetAccountAsync(Convert.ToUInt32(AccountId)));
    }
    protected async void DeleteAccount()
    {
        await accountService.DeleteAccountAsync(account);
        navigationManager.NavigateTo("Accounts/Index");
    }
    void Cancel()
    {
        navigationManager.NavigateTo("Accounts/Index");
    }
}