@inherits ViewModelTemplate<UserCreateViewModel>
@using Dynamicweb.Rendering
@using Dynamicweb.Security.UserManagement;
@using Dynamicweb.Users.Frontend.UserCreate;
@using Dynamicweb.Users.Frontend

<div class="mx-auto w-100" style="max-width: 30rem;">
    @if (Model.Result == UserCreateResultType.EmailAlreadyExists)
    {
        <div class="alert alert-danger">@Translate("The email already exists")</div>
    }
    else if (Model.Result == UserCreateResultType.InvalidEmail)
    {
        <div class="alert alert-danger">@Translate("The email is invalid")</div>
    }
    else if (Model.Result == UserCreateResultType.UserNameAlreadyExists)
    {
        <div class="alert alert-danger">@Translate("The username already exists")</div>
    }
    else if (Model.Result != UserCreateResultType.None)
    {
        <div class="alert alert-danger">@Translate(Model.Result.ToString())</div>
    }

    <form method="post">
        <input type="hidden" name="UserName" id="UserName" value="@Model.Email" />
        
        <div class="form-floating mb-4">
            <input type="text" class="form-control" placeholder="@Translate("Name")" name="Name" id="Name" value="@Model.Name" />
            <label for="Email" class="form-label">@Translate("Name")</label>
        </div>

        <div class="form-floating mb-4">
            <input type="email" class="form-control" placeholder="@Translate("Email")" name="Email" id="Email" value="@Model.Email" required />
            <label for="Email" class="form-label">@Translate("Email")</label>
        </div>

        <div class="form-floating mb-4">
            <input type="text" class="form-control" placeholder="@Translate("Customer number")" name="CustomerNumber" id="CustomerNumber" value="@Model.CustomerNumber" />
            <label for="Email" class="form-label">@Translate("Customer number")</label>
        </div>

        <button type="submit" name="Cmd" value="createuser" class="btn btn-primary w-100" data-dw-button="primary" id="CreateUser">@Translate("Create user")</button>

        @if (!string.IsNullOrEmpty(Model.LoginLink))
        {
            <div class="hstack mt-4 gap-2">
                @Translate("Already have a user profile?") 
                <span class="fw-bold">
                    <a href="@Model.LoginLink" class="text-decoration-none text-decoration-underline-hover">@Translate("Sign in")</a>
                </span>
            </div>
        }
    </form>
</div>
