@using PantheonRA.BackOffice.Models
@using PAW.Contracts.Enums
@model PantheonRA.BackOffice.Models.CreateUserViewModel
@{
    ViewBag.Title = Model.Id <= 0 ? Loc.CreateNewUser : Loc.EditUser;
}

<div class="tabs-container">
    @Html.Partial("~/Views/Company/_CompanySettingsTabNavigation.cshtml")
    <div class="tab-content">
        @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "userForm" }))
        {
            @Html.HiddenFor(model => model.Id)
            <div class="row buttons-tabbed">
                @Html.Partial("_FormButtons", new FormButtonsViewModel
                {
                    BackUrl = Url.Action("Index", "Users"),
                    SaveButtonGroup = new FormButtonGroup
                    {
                        Buttons = new List<FormButton>
                        {
                            new FormButton { Text = Loc.Save, Icon = "far fa-print fa-lg" },
                        }
                    }
                })

                <a href="@Url.Action("Create", "Users")" title="@Loc.New" id="newUserButton"
                   class="btn btn-primary btn-outline pull-right @(Model.Id > 0 ? "hidden" : string.Empty)">
                    <i class="fas fa-plus m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.New</span>
                </a>
            </div>
            <div class="divided-content clearfix">
                <div class="divided-content-main divided-content-full">
                    <div class="row">
                        <div class="col-md-4 column-full-height-border-right">
                            <div class="form-horizontal">
                                <h3 class="m-b-md m-t-md">@Loc.UserData</h3>
                                @if (Model.UserName != "admin")
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.IsActive, Loc.GridIsActive, new { @class = "col-xs-4 m-t-xxs" })
                                        <div class="col-xs-8 padding-left-none">
                                            @Html.CheckBoxFor(model => model.IsActive, new { @id = "IsActive", @class = "form-control js-switch js-switch-small" })
                                        </div>
                                    </div>
                                }
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Subject, Loc.Subject, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.Subject, HtmlAttributesHelper.CreateInputAttributes("form-control typeahead_3 typeahead_large addable-input", "Subject", false, Loc.Subject, true))
                                        @Html.ValidationMessageFor(model => model.Subject)
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Name, Loc.FirstName, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.Name, new { @id = "Name", @class = "form-control", @placeholder = Loc.FirstName, @autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.Name)
                                    </div>
                                </div>
                                <div class="form-group oib-input-group">
                                    @Html.LabelFor(model => model.Surname, Loc.LastName, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.Surname, new { @id = "Surname", @class = "form-control", @placeholder = Loc.LastName, @autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.Surname)
                                    </div>
                                </div>
                                <div class="form-group oib-input-group">
                                    @Html.LabelFor(model => model.DisplayName, PantheonRA.BackOffice.CurrentUser.Localization != Localization.Code.ME ? Loc.DisplayName : Loc.PhysicalPersonLabel, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.DisplayName, new { @id = "DisplayName", @class = "form-control", @placeholder = Loc.DisplayName, @autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.DisplayName)
                                    </div>
                                </div>
                                <div class="form-group oib-input-group">
                                    @Html.LabelFor(model => model.TaxNumber, Loc.Oib, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.TaxNumber, new { @class = "form-control", @placeholder = Loc.Oib, @autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.TaxNumber)
                                    </div>
                                </div>

                                <div class="form-group oib-input-group">
                                    @Html.LabelFor(model => model.Email, Loc.Email, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.Email, new { @id = "Email", @class = "form-control", @placeholder = Loc.Email, @autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.Email)
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4 column-full-height-border-right">
                            <div class="form-horizontal">
                                <div class="hidden-lg hidden-md">
                                    <div class="hr-line-dashed"></div>
                                </div>
                                <h3 class="m-b-md m-t-md">@Loc.LoginCredentials</h3>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.UserName, Loc.UserName, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.UserName, HtmlAttributesHelper.CreateInputAttributes("form-control", "UserName", Model.Id > 0, Loc.UserName))
                                        @Html.ValidationMessageFor(model => model.UserName)
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Password, Loc.Password, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.PasswordFor(model => model.Password, new { id = "Password", @class = "form-control", placeholder = (Model.Id > 0 ? "*****" : Loc.Password) })
                                        @Html.ValidationMessageFor(model => model.Password)
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.PasswordAgain, Loc.RePassword, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.PasswordFor(model => model.PasswordAgain, new { id = "PasswordAgain", @class = "form-control", placeholder = (Model.Id > 0 ? "*****" : Loc.Password) })
                                        @Html.ValidationMessageFor(model => model.PasswordAgain)
                                    </div>
                                </div>
                                @if (PantheonRA_Data.Configuration.POSConfig.WebPOSConfig.PawUserPasswordEncrypt.PawEncrypt == "1")
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.EncryptPasswordPaWeb, Loc.PantheonWeb, new { @class = "col-xs-4 m-t-xxs" })
                                        <div class="col-xs-8 padding-left-none">
                                            @Html.CheckBoxFor(model => model.EncryptPasswordPaWeb, new { @class = "form-control js-switch js-switch-small" })
                                        </div>
                                    </div>
                                }
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Granules, Loc.Granules, new { @class = "col-xs-4 m-t-sm" })
                                    <div class="col-xs-8 padding-left-none">
                                        @Html.TextBoxFor(model => model.Granules, new { @class = "form-control", disabled = "disabled", title = Model.Granules })
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="hidden-lg hidden-md">
                                <div class="hr-line-dashed"></div>
                            </div>
                            @if (PantheonRA.BackOffice.CurrentUser.IsAdmin)
                            {
                                <h3 class="m-b-md m-t-md">@Loc.Permissions</h3>

                                for (int i = 0; i < Model.UserRights.Count; i++)
                                {
                                    <div class="form-group m-t-sm">
                                        @Html.CheckBoxFor(model => model.UserRights[i].Checked, new { @class = "form-control js-switch permission" })
                                        @Html.HiddenFor(model => model.UserRights[i].Id)
                                        @Html.HiddenFor(model => model.UserRights[i].Text)
                                        @Html.LabelFor(model => model.UserRights[i], Model.UserRights[i].Text)
                                    </div>
                                }
                            }
                        </div>
                    </div>
                </div>
            </div>
        }
    </div>
</div>

<input id="subjectIsRequiredLoc" value="@Loc.SubjectIsRequired" hidden />
<input id="username" value="@PantheonRA.BackOffice.CurrentUser.UserName" hidden />
<input id="isFirstUser" value="@PantheonRA.BackOffice.CurrentUser.IsFirstUser.ToString()" hidden />
<input id="SearchPartnersUrl" value="@Url.Action("SearchPartners", "Wholesale")" hidden />

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

@helper PasswordTextBox(int id, string inputName, string inputValue, string placeholder)
{
    if (id > 0)
    {
        @Html.Password(inputName, inputValue, new { @id = "Oib", @class = "form-control", @placeholder = placeholder, @value = inputValue })
    }
    else
    {
        @Html.TextBox(inputName, inputValue, new { @id = "Oib", @class = "form-control", @placeholder = placeholder, @value = inputValue })
    }
}
