@using TightWiki.Models
@model TightWiki.Models.ViewModels.Admin.AccountProfileViewModel
@{
    Layout = "/Views/Shared/_Layout.cshtml";
    var sessionState = ViewData["SessionState"] as TightWiki.SessionState ?? throw new Exception("Wiki State Context cannot be null.");
}

<h3>
    Add Account
</h3>

<p>
    Create new user account.<br /><br />
</p>

@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
    <div class="alert alert-danger">@Html.Raw(Model.ErrorMessage)</div>
}
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
    <div class="alert alert-success">@Html.Raw(Model.SuccessMessage)</div>
}

@using (Html.BeginForm(null, null, new { navigation = Model.AccountProfile.Navigation }, FormMethod.Post, true, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()

    <div class="container">
        <form>
            @Html.HiddenFor(m => m.AccountProfile.Navigation)

            <div class="form-group row mb-1">
                <label for="Avatar" class="col-sm-2 col-form-label"><strong>Avatar</strong></label>
                <div class="col-sm-10">
                    <input type="file" id="Avatar" name="Avatar" class="form-control-file" onchange="fileCheck(this);" />
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="EmailAddress" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.EmailAddress)</strong></label>
                <div class="col-sm-10">
                    @Html.TextBoxFor(m => m.AccountProfile.EmailAddress, new { @class = "form-control", placeholder = "required" })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.EmailAddress)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="AccountName" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.AccountName)</strong></label>
                <div class="col-sm-10">
                    @Html.TextBoxFor(m => m.AccountProfile.AccountName, new { @class = "form-control", placeholder = "required" })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.AccountName)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="FirstName" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.FirstName)</strong></label>
                <div class="col-sm-10">
                    @Html.TextBoxFor(m => m.AccountProfile.FirstName, new { @class = "form-control", placeholder = "not required" })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.FirstName)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="LastName" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.LastName)</strong></label>
                <div class="col-sm-10">
                    @Html.TextBoxFor(m => m.AccountProfile.LastName, new { @class = "form-control", placeholder = "not required" })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.LastName)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="Role" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.Role)</strong></label>
                <div class="col-sm-10">
                    <select name="AccountProfile.Role" id="AccountProfile.Role" class="form-control">
                        <option value="" style="color:#ccc !important;">Select a role</option>
                        @foreach (var item in Model.Roles)
                        {
                            <option value="@item.Name" selected=@(Model.AccountProfile.Role == item.Name ? "selected" : null)>
                                @item.Name
                            </option>
                        }
                    </select>
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.Role)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="Country" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.Country)</strong></label>
                <div class="col-sm-10">
                    <select name="AccountProfile.Country" id="AccountProfile.Country" class="form-control">
                        <option value="" style="color:#ccc !important;">Select a country</option>
                        @foreach (var item in Model.Countries)
                        {
                            <option value="@item.Value" selected=@(Model.AccountProfile.Country == item.Value ? "selected" : null)>
                                @item.Text
                            </option>
                        }
                    </select>
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.Country)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="Language" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.Language)</strong></label>
                <div class="col-sm-10">
                    <select name="AccountProfile.Language" id="AccountProfile.Language" class="form-control">
                        <option value="" style="color:#ccc !important;">Select a language</option>
                        @foreach (var item in Model.Languages)
                        {
                            <option value="@item.Value" selected=@(Model.AccountProfile.Language == item.Value ? "selected" : null)>
                                @item.Text
                            </option>
                        }
                    </select>
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.Language)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="TimeZone" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.TimeZone)</strong></label>
                <div class="col-sm-10">
                    <select name="AccountProfile.TimeZone" id="AccountProfile.TimeZone" class="form-control">
                        <option value="" style="color:#ccc !important;">Select a time-zone</option>
                        @foreach (var item in Model.TimeZones)
                        {
                            <option value="@item.Value" selected=@(Model.AccountProfile.TimeZone == item.Value ? "selected" : null)>
                                @item.Text
                            </option>
                        }
                    </select>
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.TimeZone)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="Password" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.Credential.Password)</strong></label>
                <div class="col-sm-10">
                    @Html.PasswordFor(m => m.Credential.Password, new { @class = "form-control", value = Model.Credential.Password })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.Credential.Password)</div>
                </div>
            </div>
            <div class="form-group row mb-1">
                <label for="ComparePassword" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.Credential.ComparePassword)</strong></label>
                <div class="col-sm-10">
                    @Html.PasswordFor(m => m.Credential.ComparePassword, new { @class = "form-control", value = Model.Credential.Password })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.Credential.ComparePassword)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <label for="Biography" class="col-sm-2 col-form-label"><strong>@Html.LabelFor(m => m.AccountProfile.Biography)</strong></label>
                <div class="col-sm-10">
                    @Html.TextAreaFor(m => m.AccountProfile.Biography, new { @class = "form-control", style = "height:200px", Name = "Biography" })
                    <div class="text-danger">@Html.ValidationMessageFor(m => m.AccountProfile.Biography)</div>
                </div>
            </div>

            <div class="form-group row mb-1">
                <div class="col-sm-10 offset-sm-2">
                    <button type="submit" class="btn btn-success rounded-0">Save!</button>
                </div>
            </div>
        </form>
    </div>
}
