@using PantheonRA.BackOffice
@using PantheonRA.BackOffice.Enums
@using PantheonRA.WebApi.Contracts.Enums
@using PantheonRA.BackOffice.Models
@using PAW.Contracts.Enums;
@model PantheonRA.BackOffice.Models.PaymentMethodCreateViewModel
@{
    ViewBag.Title = string.IsNullOrEmpty(Model.Id) ? Loc.CreateNewPaymentType : Loc.EditPaymentType;
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { @id = "paymentTypeForm", enctype = "multipart/form-data" }))
{
    <div class="tabs-container">
        @Html.Partial("~/Views/Products/_CodeListTabNavigation.cshtml")
        <div class="tab-content">
            <div class="row buttons-tabbed">
                @Html.Partial("_FormButtons", new FormButtonsViewModel
                {
                    BackUrl = Url.Action("Index", "PaymentTypes"),
                    SaveButtonGroup = new FormButtonGroup
                    {
                        Buttons = new List<FormButton>
                        {
                            new FormButton { Text = Loc.Save, Icon = "fa fa-save fa-lg", IsSubmit = true, OnClick="$('#paymentTypeForm').submit();" }
                        }
                    }
                })

                <a href="@Url.Action("Create", "PaymentTypes")" title="@Loc.New"
                   class="btn btn-primary btn-outline pull-right @(string.IsNullOrEmpty(Model.Id) ? "hidden" : string.Empty)">
                    <i class="fas fa-plus m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.CreateNewPaymentType</span>
                </a>

                <button id="delete" type="button" onclick="removePaymentType()" title="@Loc.Delete"
                        class="btn btn-danger btn-outline pull-right collapsable-form-button @(Model.IsEdit ? string.Empty : " hidden")">
                    <i class="far fa-trash-alt m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.Delete</span>
                </button>
            </div>
            <div class="divided-content">
                <div class="divided-content-main divided-content-full">
                    <div class="form-horizontal form-md m-t-md">
                        <div class="row">
                            <div class="col-xs-12 col-md-7 col-lg-5">
                                <div class="row">
                                    <div class="col-xs-12">
                                        @Html.HiddenFor(model => model.IsEdit)
                                        <h3 class="m-b-md">@Loc.PaymentTypeBasicData</h3>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.Active, Loc.IsActive, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @Html.CheckBoxFor(model => model.Active, new { @id = "Active", @class = "form-control js-switch" })
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.Id, Loc.Code, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @if (!string.IsNullOrEmpty(Model.Id) && Model.IsEdit)
                                                {
                                                    @Html.TextBoxFor(model => model.Id, new { @id = "Id", @class = "form-control", @readonly = "readonly", @placeholder = Loc.Code })
                                                    @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
                                                }
                                                else
                                                {
                                                    @Html.TextBoxFor(model => model.Id, new { @id = "Id", @class = "form-control", @placeholder = Loc.Code, maxlength = "3", autocomplete = "off" })
                                                    @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
                                                }
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.Name, Loc.Name, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @Html.TextBoxFor(model => model.Name, new { @id = "Name", @class = "form-control", @placeholder = Loc.Name, autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.SetOf, Loc.Method, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @Html.DropDownListFor(model => model.SetOf, new List<SelectListItem>
                                                {
                                                    new SelectListItem{ Text = PaymentType.Cash.ToString() + " - " + Loc.PaymentCash, Value = PaymentType.Cash },
                                                    new SelectListItem{ Text = PaymentType.NonCash.ToString() + " - " + Loc.NonCash, Value = PaymentType.NonCash },
                                                }, HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "SetOf", false, Loc.Method, false))
                                            </div>
                                        </div>

                                        <div class="form-group" @(CurrentUser.Localization != Localization.Code.SI && CurrentUser.Localization != Localization.Code.HR ? "hidden" : "")>
                                            @Html.LabelFor(model => model.PaymentType, Loc.PaymentType, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @Html.DropDownListFor(model => model.PaymentType, new List<SelectListItem>
                                                {
                                                    new SelectListItem{ Text = Loc.PaymentCash, Value = PaymentType.Cash },
                                                    new SelectListItem{ Text = Loc.PaymentCerditCard, Value = PaymentType.CreditCard },
                                                    new SelectListItem{ Text = Loc.Other, Value = PaymentType.Other }
                                                }, HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "PaymentType", false, Loc.PaymentType, false))
                                            </div>
                                        </div>

                                        <div class="form-group" @(CurrentUser.Localization != Localization.Code.SI && CurrentUser.Localization != Localization.Code.RS && !Localization.IsInSecondaryServerFiscalization(CurrentUser.Localization) ? "hidden" : "")>
                                            @Html.LabelFor(model => model.FiscalGroup, Loc.FiscalGroup, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.SI)
                                                {
                                                    @Html.DropDownListFor(model => model.FiscalGroup, new List<SelectListItem>
                                                    {
                                                        new SelectListItem{ Text = Loc.PaymentCash, Value = PaymentType.Cash },
                                                        new SelectListItem{ Text = Loc.Other, Value = PaymentType.Other }
                                                    }, HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "FiscalGroup", false, Loc.FiscalGroup, false))
                                                }
                                                @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.HR)
                                                {
                                                    @Html.DropDownListFor(model => model.FiscalGroup, new List<SelectListItem>
                                                    {
                                                        new SelectListItem{ Text = Loc.HrFiscalGroupCash, Value = PaymentType.Cash },
                                                        new SelectListItem{ Text = Loc.PaymentCerditCard, Value = PaymentType.CreditCard },
                                                        new SelectListItem{ Text = Loc.PaymentCheck, Value = PaymentType.Check },
                                                        new SelectListItem{ Text = Loc.PaymentTransaction, Value = PaymentType.BankAccount },
                                                        new SelectListItem{ Text = Loc.Other, Value = PaymentType.Other }
                                                    }, HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscalGroup", false, Loc.FiscalGroup, false))
                                                }
                                                @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.ME)
                                                {
                                                    @Html.DropDownListFor(model => model.FiscalGroupMn, new List<SelectListItem>
                                                    {
                                                        new SelectListItem{ Text = Loc.BankNotePaymentMn, Value = PaymentTypeMn.BANKNOTE },
                                                        new SelectListItem{ Text = Loc.CardPaymentMn, Value = PaymentTypeMn.CARD },
                                                        new SelectListItem{ Text = Loc.BusinessCardPaymentMn, Value = PaymentTypeMn.BUSINESSCARD },
                                                        new SelectListItem{ Text = Loc.SVoucherPaymentMn, Value = PaymentTypeMn.SVOUCHER },
                                                        new SelectListItem{ Text = Loc.CompanyPaymentMn, Value = PaymentTypeMn.COMPANY },
                                                        new SelectListItem{ Text = Loc.OrderPaymentMn, Value = PaymentTypeMn.ORDER },
                                                        new SelectListItem{ Text = Loc.AdvancePaymentMn, Value = PaymentTypeMn.ADVANCE },
                                                        new SelectListItem{ Text = Loc.AccountPaymentMn, Value = PaymentTypeMn.ACCOUNT },
                                                        new SelectListItem{ Text = Loc.FactoringPaymentMn, Value = PaymentTypeMn.FACTORING },
                                                        new SelectListItem{ Text = Loc.OtherPaymentMn, Value = PaymentTypeMn.OTHER },
                                                        new SelectListItem{ Text = Loc.OtherCashPaymentMn, Value = PaymentTypeMn.OTHERCASH },
                                                    }, "", HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscalGroupMn", false, Loc.FiscalGroup, false))
                                                }
                                                @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.RS)
                                                {
                                                    @Html.DropDownListFor(model => model.FiscalGroup, new List<SelectListItem>
                                                    {
                                                        new SelectListItem{ Text = Loc.OtherPaymentRs, Value = PaymentTypeRs.Other },
                                                        new SelectListItem{ Text = Loc.CashPaymentRs, Value = PaymentTypeRs.Cash },
                                                        new SelectListItem{ Text = Loc.CardPaymentRs, Value = PaymentTypeRs.Card },
                                                        new SelectListItem{ Text = Loc.CheckPaymentRs, Value = PaymentTypeRs.Check },
                                                        new SelectListItem{ Text = Loc.WireTransferPaymentRs, Value = PaymentTypeRs.WireTransfer },
                                                        new SelectListItem{ Text = Loc.VoucherPaymentRs, Value = PaymentTypeRs.Voucher },
                                                        new SelectListItem{ Text = Loc.MobileMoneyPaymentRs, Value = PaymentTypeRs.MobileMoney }
                                                    }, "", HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscalGroup", false, Loc.FiscalGroup, false))
                                                }
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.SlipType, Loc.SlipType, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @{
                                                    var slipTypeList = new List<SelectListItem>();
                                                    slipTypeList.Add(new SelectListItem { Text = Loc.SlipTypeNoSlip, Value = SlipType.NoSlip });
                                                    slipTypeList.Add(new SelectListItem { Text = Loc.SlipTypeCheck, Value = SlipType.Check });
                                                    slipTypeList.Add(new SelectListItem { Text = Loc.SlipTypeStandingOrder, Value = SlipType.StandingOrder });
                                                    if (CurrentUser.Localization == Localization.Code.RS || CurrentUser.Localization == Localization.Code.ME)
                                                    {
                                                        slipTypeList.Add(new SelectListItem { Text = Loc.SlipTypeCard, Value = SlipType.Card });
                                                    }
                                                    if (CurrentUser.Localization == Localization.Code.SI)
                                                    {
                                                        slipTypeList.Add(new SelectListItem { Text = Loc.SlipTypeTuristVoucher, Value = SlipType.TuristVoucher });
                                                    }
                                                }

                                                @Html.DropDownListFor(model => model.SlipType, slipTypeList, HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "SlipType", false, Loc.SlipType, false))
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.Icon, Loc.Icon, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @if (Model.IconByte != null && Model.IconByte.Length > 0)
                                                {
                                                    <img class="image-payment-type" src="data:image/png;base64,@System.Convert.ToBase64String(Model.IconByte)" />
                                                }
                                                <input name="Icon" type="file" class="dropify" data-allowed-file-extensions="png jpg jpeg" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}

<input type="hidden" id="YesLoc" value="@Loc.Yes" />
<input type="hidden" id="NoLoc" value="@Loc.No" />
<input type="hidden" id="DragAndDropOrClick" value="@Loc.UploadImageMessage" />
<input type="hidden" id="Remove" value="@Loc.Remove" />
<input type="hidden" id="GeneralErrorMessage" value="@Loc.GeneralError" />
<input type="hidden" id="WrongImageFormat" value="@Loc.WrongImageFormat" />
<input type="hidden" id="RemovePaymentTypesUrl" value="@Url.Action("Remove", "PaymentTypes")" />
<input type="hidden" id="PaymentTypesIndexUrl" value="@Url.Action("Index", "PaymentTypes")" />
<input type="hidden" id="DeleteWasNotSuccessfulLoc" value="@Loc.PaymentMethodAlreadyInUse" />
<input type="hidden" id="ConfirmDeleteLoc" value="@Loc.ConfirmDeleteMessage" />
<input type="hidden" id="ConfirmLoc" value="@Loc.Confirm" />

@section pageScripts{
    @Scripts.Render("~/bundles/product")
    <script>
        $(document).ready(function () {
            initializePaymentTypesEdit();
        });
    </script>
}