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

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

@section Header { @Model.Name }

@section Subheader { Import type details }


@using (Html.BeginForm("Edit", "ImportType", FormMethod.Post))
{
<div>

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

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

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

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

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

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

    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h2>
                Import processing rules
            </h2>
        </div>
        <div class="order-lg-2 p-0">
            @if (Model.ImportProcessingRulesAreAvailableToAdd)
            {
                @Html.ActionLink("Add an import processing rule", "Create", "ImportTypeImportProcessingRule", new { id = Model.Id }, new { @class = "btn btn-primary" })
            }
        </div>
    </div>
        
    <div class="row mb-3">
        @Html.Action("_EditList", "ImportTypeImportProcessingRule", new { id = Model.Id })
    </div>
        
    <input type="submit" value="Save" class="btn btn-primary" />
    @Html.ActionLink("Back", "Back", "ImportType", null, new { @class = "btn btn-secondary" })    

</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 data type',
                dropdownArrow: () => paymentsAdmin.controls.autocomplete.downarrow,
                selectElement: document.querySelector('#DataType')
            });

        });
    </script>
}
