@model PantheonRA.BackOffice.Models.SyncTaxCreateViewModel
@{
    ViewBag.Title = Model.SyncTaxData.Id <= 0 ? "New tax link" : "Edit tax link";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <a class="navbar-minimalize btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
        <h2>@ViewBag.Title</h2>
        <span class="breadcrumb-divider">&bull;</span>
        <ol class="breadcrumb">
            <li><a href="@Url.Action("Index", "SynchronizationSettings")">Home</a></li>
            <li>@Loc.AdministrationPanel</li>
            <li class="active"><strong>@ViewBag.Title</strong></li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>

<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="row">

        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>Synchronization Tax Settings</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-12">

                            @if (Model.SyncTaxData.Id > 0)
                            {
                                <h1>Edit data</h1>
                            }
                            else
                            {
                                <h2>New data</h2>
                            }

                            <div class="hr-line-dashed"></div>

                            @using (Html.BeginForm())
                            {
                                @Html.HiddenFor(model => model.SyncTaxData.Id)
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="col-md-6 col-sm-6">
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.SyncTaxData.TaxGroupId, "Tax group")
                                                @Html.DropDownListFor(model => model.SyncTaxData.TaxGroupId, new SelectList(Model.TaxGroupComboData, "TaxGroupId", "TaxGroup", null), "Select Tax Group", new { @id = "SelectedTaxGroupId", @class = "form-control", @onchange = "FillTax()"})
                                                @Html.ValidationMessageFor(model => model.SyncTaxData.TaxGroupId)
                                            </div>
                                        </div>
                                        <div class="col-md-6 col-sm-6">
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.SyncTaxData.TaxId, "Tax")
                                                @Html.DropDownListFor(model => model.SyncTaxData.TaxId, new List<SelectListItem>(), "Select Tax", new { @id = "SelectedTaxId", @class = "form-control" })
                                                @Html.ValidationMessageFor(model => model.SyncTaxData.TaxId)
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="col-md-6 col-sm-6">
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.SyncTaxData.PACode, "Pantheon Code")
                                                @Html.TextBoxFor(model => model.SyncTaxData.PACode, new { @id = "PACode", @class = "form-control", @placeholder = "Pantheon code" + "...", maxlength=10 })
                                                @Html.ValidationMessageFor(model => model.SyncTaxData.PACode)
                                            </div>
                                        </div>
                                        <div class="col-md-3 col-sm-3">
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.SyncTaxData.PaToRc, "Pantheon to RC")
                                                @Html.CheckBoxFor(model => model.SyncTaxData.PaToRc, new { @id = "PaToRc", @class = "form-control" })
                                                @Html.ValidationMessageFor(model => model.SyncTaxData.PaToRc)
                                            </div>
                                        </div>
                                        <div class="col-md-3 col-sm-3">
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.SyncTaxData.PACode, "RC to Pantheon")
                                                @Html.CheckBoxFor(model => model.SyncTaxData.RcToPa, new { @id = "RcToPa", @class = "form-control" })
                                                @Html.ValidationMessageFor(model => model.SyncTaxData.RcToPa)
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="hr-line-dashed"></div>
                                        <div class="row buttons-row">
                                            <div class="col-xs-4">
                                                <a href="@Url.Action("Index", "SynchronizationSettings")" class="btn btn-default btn-block btn-outline">@Loc.Cancel</a>
                                            </div>
                                            <div class="col-xs-1 col-xs-offset-1">

                                            </div>
                                            <div class="col-xs-6">
                                                <button id="saveImportedItems2" class="btn btn-primary btn-block" type="submit">
                                                    <div class="text-center" id="insertingProductsLoader2" style="display: none;">
                                                        <div class="sk-spinner sk-spinner-three-bounce">
                                                            <div class="sk-bounce1"></div>
                                                            <div class="sk-bounce1"></div>
                                                            <div class="sk-bounce2"></div>
                                                        </div>
                                                    </div>
                                                    <span>@Loc.Save</span>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section pageCss{

}

@section pageScripts{
    <script type="text/javascript">
        function FillTax() {
            var currentGroupId = $('#SelectedTaxGroupId').val();
            var json = @Html.Raw(Json.Encode(Model.TaxGroupComboData));
            for (var i = 0; i < json.length; i++) {
                if (json[i].TaxGroupId == currentGroupId) {
                    $("#SelectedTaxId").html(""); // clear before appending new list
                    $.each(json[i].Taxes, function (i, tax) {
                        $("#SelectedTaxId").append(
                            $('<option></option>').val(tax.TaxId).html(tax.Tax));
                    });
                    break;
                }
            }
        }

        $(document).ready(function () {
            $('.input-validation-error').parents('.form-group').addClass('has-error');
            $('.field-validation-error').addClass('text-danger');
            FillTax();
            @if (Model.SyncTaxData.TaxId != null && Model.SyncTaxData.TaxId > 0)
            {
                @:$("#SelectedTaxId").val = @Model.SyncTaxData.TaxId;
            }

        });

    </script>
}