@page "/admin/webspaces/servers/new"
@using Moonlight.App.Repositories
@using Moonlight.App.Models.Forms
@using Moonlight.App.Database.Entities
@using Mappy.Net

@inject Repository<CloudPanel> CloudPanelRepository
@inject NavigationManager NavigationManager

@attribute [PermissionRequired(nameof(Permissions.AdminWebspacesServerNew))]

<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>Host</TL>
            </label>
            <div class="input-group mb-5">
                <InputText @bind-Value="Model.Host" 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>

@code
{
    private CloudPanelDataModel Model = new();

    private Task OnValidSubmit()
    {
        CloudPanelRepository.Add(Mapper.Map<CloudPanel>(Model));

        NavigationManager.NavigateTo("/admin/webspaces/servers");

        return Task.CompletedTask;
    }
}