@page "/CustomDescriptions/Edit/{CustomDescriptionId}"

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

@inject CustomDescriptionService customDescriptionservice
@inject NavigationManager navigationManager

<h2>Edit CustomDescription</h2>
<hr />

<form>
    <div class="row">
        <div class="col-md-8">
            <div class="form-group">
                <label for="CustomDescriptionId" class="control-label">CustomDescriptionId</label>
                <input form="CustomDescriptionId" class="form-control" @bind="@customDescription.CustomDescriptionId" />
            </div>
            <div class="form-group">
                <label for="ProductNumber" class="control-label">ProductNumber</label>
                <input form="ProductNumber" class="form-control" @bind="@customDescription.ProductNumber" />
            </div>
            <div class="form-group">
                <label for="OptionNumber" class="control-label">OptionNumber</label>
                <input form="OptionNumber" class="form-control" @bind="@customDescription.OptionNumber" />
            </div>
            <div class="form-group">
                <label for="Heading" class="control-label">Heading</label>
                <input form="Heading" class="form-control" @bind="@customDescription.Heading" />
            </div>
            <div class="form-group">
                <label for="DescriptionText" class="control-label">DescriptionText</label>
                <input form="DescriptionText" class="form-control" @bind="@customDescription.DescriptionText" />
            </div>
        </div>
    </div>

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

@code {
    [Parameter]
    public string? customDescriptionId { get; set; }
    CustomDescription customDescription = new CustomDescription();

    protected override async Task OnInitializedAsync()
    {
        customDescription = await Task.Run(() => customDescriptionservice.GetCustomDescriptionAsync(Convert.ToUInt32(customDescriptionId)));
    }

    protected async void UpdateCustomDescription()
    {
        customDescription.DataModificationByUser = "Gremlin_BlazorServer";
        customDescription.DataModificationDate = DateTime.Now;
        customDescription.DataVersionNumber++;
        await customDescriptionservice.UpdateCustomDescriptionAsync(customDescription);
        navigationManager.NavigateTo("CustomDescriptions/Index");
    }

    void Cancel() => navigationManager.NavigateTo("CustomDescriptions/Index");
}