@model UrlRecordSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.System.SeNames").Text;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("Search engine friendly names");
}

@{
    const string hideSearchBlockAttributeName = "UrlRecordPage.HideSearchBlock";
    var hideSearchBlock = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideSearchBlockAttributeName);
}

<div class="content-header clearfix">
    <h1 class="float-left">
        @T("Admin.System.SeNames")
    </h1>
    <div class="float-right">
        <button type="button" id="delete-selected" class="btn btn-danger">
            <i class="far fa-trash-alt"></i>
            @T("Admin.System.SeNames.DeleteSelected")
        </button>
        <nop-action-confirmation asp-button-id="delete-selected" />
        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SenamesButtons, additionalData = Model })
    </div>
</div>

<section class="content">
    <div class="container-fluid">
    <div class="form-horizontal">
        <div class="cards-group">
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SenamesTop, additionalData = Model })
            <div class="card card-default card-search">
                <div class="card-body">
                    <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                        <div class="search-text">@T("Admin.Common.Search")</div>
                        <div class="icon-search"><i class="fas fa-search" aria-hidden="true"></i></div>
                        <div class="icon-collapse"><i class="far fa-angle-@(!hideSearchBlock ? "up" : "down")" aria-hidden="true"></i></div>
                    </div>

                    <div class="search-body @(hideSearchBlock ? "closed" : "")">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <nop-label asp-for="SeName" />
                                    </div>
                                    <div class="col-md-8">
                                        <nop-editor asp-for="SeName" />
                                    </div>
                                </div>
								<div class="form-group row">
                                    <div class="col-md-4">
                                        <nop-label asp-for="LanguageId" />
                                    </div>
                                    <div class="col-md-8">
                                        <nop-select asp-for="LanguageId" asp-items="Model.AvailableLanguages" />
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <nop-label asp-for="IsActiveId" />
                                    </div>
                                    <div class="col-md-8">
                                        <nop-select asp-for="IsActiveId" asp-items="Model.AvailableActiveOptions" />
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-md-8 offset-md-4">
                                        <button type="button" id="search-senames" class="btn btn-primary btn-search"><i class="fas fa-search"></i>@T("Admin.Common.Search")</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card card-default">
                <div class="card-body">
                    <nop-doc-reference asp-string-resource="@T("Admin.Documentation.Reference.SeoOptimization", Docs.SeoOptimization + Utm.OnAdmin)" />

                    @await Html.PartialAsync("Table", new DataTablesModel
                    {
                        Name = "sename-grid",
                        UrlRead = new DataUrl("SeNames", "Common", null),
                        SearchButtonId = "search-senames",
                        Length = Model.PageSize,
                        LengthMenu = Model.AvailablePageSizes,
                        Filters = new List<FilterParameter>
                        {
                            new FilterParameter(nameof(Model.SeName)),
                            new FilterParameter(nameof(Model.LanguageId)),
                            new FilterParameter(nameof(Model.IsActiveId))
                        },
                        ColumnCollection = new List<ColumnProperty>
                        {
                            new ColumnProperty(nameof(UrlRecordModel.Id))
                            {
                                IsMasterCheckBox = true,
                                Render = new RenderCheckBox("checkbox_senames"),
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Width = "50"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.Id))
                            {
                                Title = T("Admin.System.SeNames.Id").Text,
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Width = "50"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.Name))
                            {
                                Title = T("Admin.System.SeNames.Name").Text
                            },
                            new ColumnProperty(nameof(UrlRecordModel.EntityId))
                            {
                                Title = T("Admin.System.SeNames.EntityId").Text,
                                Width = "80"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.EntityName))
                            {
                                Title = T("Admin.System.SeNames.EntityName").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.IsActive))
                            {
                                Title = T("Admin.System.SeNames.IsActive").Text,
                                Width = "80",
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Render = new RenderBoolean()
                            },
                            new ColumnProperty(nameof(UrlRecordModel.Language))
                            {
                                Title = T("Admin.System.SeNames.Language").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.DetailsUrl))
                            {
                                Title = T("Admin.System.SeNames.Details").Text,
                                Width = "100",
                                ClassName = NopColumnClassDefaults.Button,
                                Render = new RenderCustom("renderColumnDetailsUrl")
                            }
                        }
                    })
                </div>
            </div>
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SenamesBottom, additionalData = Model })
        </div>
    </div>
</div>
</section>
<script>
    function renderColumnDetailsUrl(data, type, row, meta) {
        if (row.DetailsUrl && row.DetailsUrl.length > 0) {
            return '<a class="btn btn-default" href="' + row.DetailsUrl + '"><i class="fas fa-pencil-alt"></i>@T("Admin.System.SeNames.Details").Text</a>';
        }
        else {
            return '';
        }
    }
</script>
<script>
    $(document).ready(function() {
        //"delete selected" button
        $("#delete-selected-action-confirmation-submit-button").bind("click", function () {
            var postData = {
                selectedIds: selectedIds
            };
            addAntiForgeryToken(postData);
            $.ajax({
                cache: false,
                type: "POST",
                url: "@(Url.Action("DeleteSelectedSeNames", "Common"))",
                data: postData,
                traditional: true,
                error: function (jqXHR, textStatus, errorThrown) {
                    showAlert('deleteSelectedSeNamesFailed', errorThrown);
                },
                complete: function (jqXHR, textStatus) {
                    if (jqXHR.status === 204)
                    {
                        showAlert('nothingSelectedAlert', '@T("Admin.Common.Alert.NothingSelected")');
                        return;
                    }
                    updateTable('#sename-grid');
                }
            });
            $('#delete-selected-action-confirmation').modal('toggle');
            return false;
        });
    });
</script>
<nop-alert asp-alert-id="deleteSelectedSeNamesFailed" />
<nop-alert asp-alert-id="nothingSelectedAlert" />