@page "/Accounts/Add"

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

@inject AccountService accountService
@inject NavigationManager navigationManager

<h2>Add Account</h2>
<hr />

<form>
    <div class="row">
        <div class="col-md-8">
            <div class="form-group">
                <label for="SAPAccountNumber" class="control-label">SAPAccountNumber</label>
                <input form="SAPAccountNumber" class="form-control" @bind="@account.SAPAccountNumber" />
            </div>
            <div class="form-group">
                <label for="AccountName" class="control-label">AccountName</label>
                <input form="AccountName" class="form-control" @bind="@account.AccountName" />
            </div>
            <div class="form-group">
                <label for="Street" class="control-label">Street</label>
                <input form="Street" class="form-control" @bind="@account.Street" />
            </div>
            <div class="form-group">
                <label for="ZIP" class="control-label">ZIP</label>
                <input form="ZIP" class="form-control" @bind="@account.ZIP" />
            </div>
            <div class="form-group">
                <label for="City" class="control-label">City</label>
                <input form="City" class="form-control" @bind="@account.City" />
            </div>

        </div>
    </div>

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

@code {
    Account account = new Account();

    protected async void CreateAccount()
    {
        account.DataModificationByUser = "Gremlin_BlazorServer";
        account.AccountType.AccountTypeCode = "SUP";

        if (await accountService.InsertAccountAsync(account))
        {
            navigationManager.NavigateTo("Accounts/Index");
        }
    }

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