@model PantheonRA.BackOffice.Models.WholesaleSettingsViewModel
@using PantheonRA.WebApi.Contracts
@{
    ViewBag.Title = @Loc.DefaultSettings;
}

<div class="tabs-container">
    @Html.Partial("~/Views/Company/_CompanySettingsTabNavigation.cshtml")
    <div class="divided-content clearfix">
        <div class="divided-content-main divided-content-full">
            <div class="form-horizontal form-md m-t-md">
                <h3>@ViewBag.Title</h3>
                <div class="inline font-bold">
                    @Html.LabelFor(model => model.DocType, @Loc.DocType, new { @class = "control-label" })
                </div>
                <div class="inline m-l-sm">
                    @Html.DropDownListFor(model => model.DocType, Model.DocumentTypesList.Select(x => new SelectListItem { Text = x.Value, Value = x.Id }), "",
                        new { @id = "DocumentSelectList", @onchange = "ChangeDocument(this.value)", @class = "form-control custom-select" })
                </div>
                <div class="inline">
                    <i class='fa fa-spinner fa-spin'></i>
                </div>
            </div>
        </div>
    </div>
</div>

@section pageScripts{
    <script>
        $(document).ready(function () {
        var documentDd = $("#DocumentSelectList");
        var loading = $(".fa-spinner").hide();

        $(document)
            .ajaxStart(function () {
                loading.show();
                documentDd.prop("disabled", true);

            })
            .ajaxStop(function () {
                loading.hide();
                documentDd.prop("disabled", false);
            });
        });

        function ChangeDocument(val) {
            var url = '@Url.Action("SaveSettings", "Settings")';
            $.ajax({
                url: url,
                type: "post",
                data: {
                    dropDownName: "@DefaultSettingsTypes.DefaultWholesaleDocumentType",
                    selectedValue: val
                },
                success: function () {
                    toastr.success("@Loc.DocumentSettingsDropDownAjaxSuccess");
                },
                error: function () {
                    toastr.warning("@Loc.DocumentSettingsDropDownAjaxFail");
                }
            });
        }
    </script>
}
