@page "/Contacts/Delete/{ContactId}"

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

@inject ContactService contactService
@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>ContactId:</label>
                <label>@contact.ContactId</label>
            </div>
            <div class="form-group">
                <label>ContactId:</label>
                <label>@contact.ContactId</label>
            </div>
            <div class="form-group">
                <label>LastName:</label>
                <label>@contact.LastName</label>
            </div>
            <div class="form-group">
                <label>FirstName:</label>
                <label>@contact.FirstName</label>
            </div>
            <div class="form-group">
                <label>Gender:</label>
                <label>@contact.Gender</label>
            </div>
            <div class="form-group">
                <label>EMail:</label>
                <label>@contact.EMail</label>
            </div>            
            <div class="form-group">
                <label>SAPContactNumber:</label>
                <label>@contact.SAPContactNumber</label>
            </div>
        </div>

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

@code {
    [Parameter]
    public string contactId { get; set; } = default!;
    Contact contact = new Contact();

    protected override async Task OnInitializedAsync()
    {
        contact = await Task.Run(() => contactService.GetContactAsync(Convert.ToUInt32(contactId)));
    }
    protected async void DeleteContact()
    {
        await contactService.DeleteContactAsync(contact);
        navigationManager.NavigateTo("Contacts/Index");
    }
    void Cancel()
    {
        navigationManager.NavigateTo("Contacts/Index");
    }
}