@using PantheonRA.BackOffice.Enums
@using PAW.Contracts.Enums
@using PantheonRA.BackOffice

@inherits PantheonRA.BackOffice.Pages.AuthPage<PantheonRA.BackOffice.Models.SubjectsGridFilterModel>
@{
    ViewBag.Title = Loc.Subjects;
    var userCanAccessSubjectsCud = _authInfo.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.SIFPART);
    var isLicenseWP = CurrentUser.LicenseType() == LicenseTypes.LicenseType.WP;
}

@Html.Hidden("isLicenseWP", isLicenseWP)
@Html.Hidden("SubjectsExampleLicenseWPHelpUrl", SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ExampleSubjects))
@Html.Hidden("SubjectsLicenseWPHelpUrl", SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ManualSubjects))

<div class="wrapper wrapper-content">
    <div class="tabs-container">
        @Html.Partial("~/Views/Products/_CodeListTabNavigation.cshtml")
        <div class="row buttons-tabbed">
            @if (userCanAccessSubjectsCud)
            {
                if (_authInfo.CanUpdate(PantheonRA.WebApi.Contracts.Enums.Permissions.SIFPART))
                {
                    <a href="@Url.Action("Create", "Subjects")" id="createSubjectButton" class="btn btn-primary btn-outline" title="@Loc.CreateNewSubject">
                        <i class="fa fa-plus"></i><span class="bold hidden-xs m-l-xs">@Loc.CreateNewSubject</span>
                    </a>

                    <div class="btn-group dropdown">
                        <button type="button"
                                id="importButton"
                                class="btn btn-primary btn-outline printDropdown"
                                onClick="importSubjectsClick()"
                                title="@Loc.ImportSubjects">
                            <i class="fas fa-cloud-upload-alt"></i><span class="visible-lg-inline visible-md-inline m-l-xs">@Loc.ImportSubjects</span>
                        </button>
                        <button type="button" class="btn btn-primary btn-outline dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="@Url.Action("DownloadSubjectsImportTemplate", "Subjects")" class="btn btn-primary btn-outline" title="@Loc.DownloadImportTemplate">
                                    <span>@Loc.DownloadImportTemplate</span>
                                </a>
                            </li>
                            <li>
                                <a onClick="importSubjectsClick()" class="btn btn-primary btn-outline" title="@Loc.ImportSubjects">
                                    <span>@Loc.ImportSubjects</span>
                                </a>
                            </li>
                        </ul>
                    </div>
                }
            }
        </div>

        <div class="row document-head">
            <div class="col-md-3">
                <div class="form-group">
                    <label class="control-label">@Loc.SearchFilter</label>
                    @Html.TextBoxFor(model => model.Keywords, new { @id = "Keywords", @class = "form-control search-input", @placeholder = Loc.Search, autocomplete = "off" })
                </div>
            </div>
            <div class="col-md-2 col-xs-6">
                <div class="form-group">
                    <label class="control-label">@Loc.Status</label>
                    @Html.DropDownListFor(model => model.Status, new SelectList(ViewBag.ActiveStatuses != null ? ViewBag.ActiveStatuses : new List<string>(), "Value", "Text"),
                    HtmlAttributesHelper.CreateInputAttributes("form-control search-addon custom-select", "Status", false))
                </div>
            </div>
            <div class="col-md-2 col-xs-6">
                <div class="form-group">
                    <label class="control-label">@Loc.TypeOfSubject</label>
                    <select id="Type" name="Type" class="form-control search-addon custom-select">
                        <option value="@SubjectType.All">@Loc.All</option>
                        <option value="@SubjectType.Buyer">@Loc.Buyers</option>
                        <option value="@SubjectType.Supplier">@Loc.Suppliers</option>
                        <option value="@SubjectType.BuyerAndSupplier">@Loc.BuyersAndSuppliers</option>
                        <option value="">@Loc.NoType</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="project-list">
            <div class="document-list document-list-no-footer">
                <table id="grid-data" data-grid-id="subjects" data-url="@Url.Action("SubjectList", "Subjects")" class="list-table">
                    <thead>
                        <tr>
                            <th width="5%">@Loc.Active</th>
                            <th width="20%" data-url="@Url.Action("Edit", "Subjects")?id=">@Loc.Code</th>
                            <th width="30%">@Loc.Name</th>
                            <th width="20%">@Loc.Address</th>
                            <th width="10%">@Loc.Oib</th>
                            <th width="15%">@Loc.TypeOfSubject</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="openSubjectUrl" value="@Url.Action("Edit", "Subjects")" />
<input type="hidden" id="userCanAccessSubjectsCud" value="@userCanAccessSubjectsCud.ToString()" />
<input type="hidden" value="@_authInfo.IsGDPR().ToString()" id="isGDPR" />
<input type="hidden" value="@Url.Action("ImportSubjects", "Subjects")" id="importSubjectsUrl" />
<input type="hidden" value="@Loc.Buyer" id="BuyerLoc" />
<input type="hidden" value="@Loc.Supplier" id="SupplierLoc" />
<input type="hidden" value="@Loc.BuyerAndSupplier" id="BuyerAndSupplier" />
<input type="hidden" value="@Localization.Code.HR" id="LocCodeHR" />
<input type="hidden" value="@PantheonRA.BackOffice.CurrentUser.Localization" id="CurrentUserLoc" />

@section pageScripts{
    @Scripts.Render("~/bundles/product")
    <script>
        $(document).ready(function () {
            initializeSubjects();
            if ($("#isLicenseWP").val() === "True") {
                setGlobalHelpUrl($("#SubjectsLicenseWPHelpUrl").val())
                setGlobalExampleHelpUrl($("#SubjectsExampleLicenseWPHelpUrl").val())
            }
        });
    </script>
}
