LocalGovIMS_localgov-ims/src/Admin/Views/User/Edit.cshtml
@model Admin.Models.User.EditViewModel
@{
    ViewBag.Title = "Edit user";
}

@section Messages {
    @if (TempData.ContainsKey("Message") && TempData["Message"] != null) { Html.RenderPartial("_Message", TempData["Message"]); }
}

@section Header { @Model.UserName }

@section Subheader { User details }

@using (Html.BeginForm("Edit", "User", FormMethod.Post))
{
    @Html.HiddenFor(m => m.UserId)

<div>

    <div class="row mb-3">
        <div class="col col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.UserName, new { @class = "form-label" })
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.UserName)
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.DisplayName, new { @class = "form-label" })
            @Html.TextBoxFor(m => m.DisplayName, new { @class = "form-control" })
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.DisplayName)
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.OfficeCode, new { @class = "form-label" })
            <select id="OfficeCode" name="OfficeCode">
                <option value="">None</option>
                @foreach (var item in Model.Offices.Items)
                {
                    <option class="item" value="@item.Value" @(!string.IsNullOrEmpty(Model.OfficeCode) && Model.OfficeCode.Equals(item.Value) ? "selected" : String.Empty)>@item.Text</option>
                }
            </select>
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.OfficeCode)
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.LastLogin, new { @class = "form-label" })
            <div class="form-label">
                @Html.DisplayFor(m => m.LastLogin)
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.ExpiryDays, new { @class = "form-label" })
            @Html.TextBoxFor(m => m.ExpiryDays, new { @class = "form-control" })
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.ExpiryDays)
            </div>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.Disabled, new { @class = "form-label" })
            <div class="form-check form-switch">
                @Html.CheckBoxFor(m => m.Disabled, new { @class = "form-check-input", role = "switch" })
            </div>
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.Disabled)
            </div>
        </div>
    </div>

    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h2>
                User roles
            </h2>
        </div>
        <div class="order-lg-2 p-0">
            @Html.ActionLink("Edit roles", "Edit", "UserRole", new { id = Model.UserId }, new { @class = "btn btn-primary" })
        </div>
    </div>

    <div class="mb-3">
        @Html.Action("_ListForUser", "UserRole", new { id = Model.UserId })
    </div>

    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h2>
                User fund groups
            </h2>
        </div>
        <div class="order-lg-2 p-0">
            @Html.ActionLink("Edit fund groups", "Edit", "UserFundGroup", new { id = Model.UserId }, new { @class = "btn btn-primary" })
        </div>
    </div>

    <div class="mb-3">
        @Html.Action("_ListForUser", "UserFundGroup", new { id = Model.UserId })
    </div>

    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h2>
                User templates
            </h2>
        </div>
        <div class="order-lg-2 p-0">
            @Html.ActionLink("Edit templates", "Edit", "UserTemplate", new { id = Model.UserId }, new { @class = "btn btn-primary" })
        </div>
    </div>

    <div class="mb-3">
        @Html.Action("_ListForUser", "UserTemplate", new { id = Model.UserId })
    </div>

    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h2>
                User methods of payment
            </h2>
        </div>
        <div class="order-lg-2 p-0">
            @Html.ActionLink("Edit methods of payment", "Edit", "UserMethodOfPayment", new { id = Model.UserId }, new { @class = "btn btn-primary" })
        </div>
    </div>

    <div class="mb-3">
        @Html.Action("_ListForUser", "UserMethodOfPayment", new { id = Model.UserId })
    </div>

    <div>
        <input type="submit" value="Save" class="btn btn-primary" />
        @Html.ActionLink("Back", "Back", "User", null, new { @class = "btn btn-secondary" })
    </div>

</div>
}

@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {

            accessibleAutocomplete.enhanceSelectElement({
                displayMenu: 'overlay',
                autoSelect: false,
                confirmOnBlur: false,
                showAllValues: true,
                defaultValue: '',
                preserveNullOptions: true,
                placeholder: 'Select office code',
                dropdownArrow: () => paymentsAdmin.controls.autocomplete.downarrow,
                selectElement: document.querySelector('#OfficeCode')
            });

        });
    </script>
}
