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

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

@section Header { @Model.FundGroupName }

@section Subheader { Fund group details }

@using (Html.BeginForm("Edit", "FundGroup", FormMethod.Post))
{

    @Html.HiddenFor(m => m.Id)

    <div>

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

        <div class="table-responsive">
            <table class="table table-striped table-bordered table-hover mt-2">
                <thead>
                    <tr>
                        <th scope="col">
                            Funds
                        </th>
                    </tr>
                </thead>

                @if (Model.Funds != null && Model.Funds.Any())
                {
                    var funds = Model.Funds.OrderBy(x => x.Text).ToList();
                    for (var i = 0; i < funds.Count(); i++)
                    {
                        <tr>
                            <td>
                                @Html.HiddenFor(x => funds[i].Id)
                                @Html.HiddenFor(x => funds[i].Text)
                                <div class="form-check form-switch">
                                    @Html.CheckBoxFor(x => funds[i].IsChecked, new { @class = "form-check-input", role = "switch" })
                                    @Html.Label(funds[i].Text, new { @for = "funds_" + i + "__IsChecked", @class = "form-check-label" })
                                </div>
                            </td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td>
                            No available funds
                        </td>
                    </tr>
                }
            </table>
        </div>

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

    </div>

}
