@page "/admin/websites/servers/new"
@using Moonlight.App.Repositories
@using Moonlight.App.Models.Forms

@inject PleskServerRepository PleskServerRepository
@inject NavigationManager NavigationManager

<OnlyAdmin>
    <div class="card card-body p-10">
        <SmartForm Model="Model" OnValidSubmit="OnValidSubmit">
            <label class="form-label">
                <TL>Name</TL>
            </label>
            <div class="input-group mb-5">
                <InputText @bind-Value="Model.Name" class="form-control"></InputText>
            </div>
            <label class="form-label">
                <TL>Api Url</TL>
            </label>
            <div class="input-group mb-5">
                <InputText @bind-Value="Model.ApiUrl" class="form-control"></InputText>
            </div>
            <label class="form-label">
                <TL>Api Key</TL>
            </label>
            <div class="input-group mb-5">
                <InputText @bind-Value="Model.ApiKey" class="form-control"></InputText>
            </div>
            <div>
                <button type="submit" class="btn btn-primary float-end">
                    <TL>Create</TL>
                </button>
            </div>
        </SmartForm>
    </div>
</OnlyAdmin>

@code
{
    private PleskServerDataModel Model = new();

    private Task OnValidSubmit()
    {
        PleskServerRepository.Add(new()
        {
            Name = Model.Name,
            ApiUrl = Model.ApiUrl,
            ApiKey = Model.ApiKey
        });
        
        NavigationManager.NavigateTo("/admin/websites/servers");

        return Task.CompletedTask;
    }
}