@model CourseSearchModel


@using Nop.Plugin.Misc.SimpleLMS.Areas.Admin.Models

@inject INopHtmlHelper NopHtml

@{
    //page title
    ViewBag.PageTitle = T("SimpleLMS.CourseList").Text;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("SimpleLMS.Courses");
}

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


<form asp-controller="Course" asp-action="List" method="post">
    <div class="content-header clearfix">
        <h1 class="float-left">
            @T("SimpleLMS.CourseList")
        </h1>
        <div class="float-right">
            <a asp-action="Create" class="btn btn-primary">
                <i class="fas fa-plus-square"></i>
                @T("Admin.Common.AddNew")
            </a>
            @*<button type="button" id="delete-selected" class="btn btn-danger">
                    <i class="far fa-trash-alt"></i>
                    @T("Admin.Common.Delete.Selected")
                </button>*@
            @*<nop-action-confirmation asp-button-id="delete-selected" />*@
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <div class="form-horizontal">
                <div class="cards-group">
                    <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-5">
                                        <div class="form-group row">
                                            <div class="col-md-4">
                                                <nop-label asp-for="SearchCourseName" />
                                            </div>
                                            <div class="col-md-8">
                                                <nop-editor asp-for="SearchCourseName" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="text-center col-12">
                                        <button type="button" id="search-courses" class="btn btn-primary btn-search">
                                            <i class="fas fa-search"></i>
                                            @T("Admin.Common.Search")
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card card-default">
                        <div class="card-body">


                            @await Html.PartialAsync("Table", new DataTablesModel
                            {
                                Name = "courses-grid",
                                UrlRead = new DataUrl("CourseList", "Course", null),
                                SearchButtonId = "search-courses",
                                Length = Model.PageSize,
                                LengthMenu = Model.AvailablePageSizes,
                                Filters = new List<FilterParameter>
                                                                {
                                    new FilterParameter(nameof(Model.SearchCourseName))
                                },
                                ColumnCollection = new List<ColumnProperty>
                                                                {
                                    new ColumnProperty(nameof(CourseModel.Id))
                                    {
                                        IsMasterCheckBox = true,
                                        Render = new RenderCheckBox("checkbox_courses"),
                                        ClassName =  NopColumnClassDefaults.CenterAll,
                                        Width = "50"
                                    },

                                   new ColumnProperty(nameof(CourseModel.Name))
                                   {
                                       Title = T("SimpleLMS.Name").Text
                                   },

                                   new ColumnProperty(nameof(CourseModel.Instructor))
                                   {
                                       Title = T("SimpleLMS.Instructor").Text
                                   },

                                   new ColumnProperty(nameof(CourseModel.Category))
                                   {
                                       Title = T("SimpleLMS.Category").Text
                                   },

                                   new ColumnProperty(nameof(CourseModel.SectionsTotal))
                                   {
                                       Title = T("SimpleLMS.Sections").Text
                                   },

                                   new ColumnProperty(nameof(CourseModel.EnrolledStudents))
                                   {
                                       Title = T("SimpleLMS.EnrolledStudents").Text
                                   },

                                   new ColumnProperty(nameof(CourseModel.Status))
                                   {
                                       Title = T("SimpleLMS.Status").Text
                                   },

                                   new ColumnProperty(nameof(CourseModel.Price))
                                   {
                                       Title = T("SimpleLMS.Price").Text
                                   },


                                    new ColumnProperty(nameof(CourseModel.Id))
                                    {
                                        Title = T("Admin.Common.Edit").Text,
                                        Width = "80",
                                        ClassName =  NopColumnClassDefaults.Button,
                                        Render = new RenderButtonEdit(new DataUrl("Edit"))
                                    }
                                }
                            })

                            <script>


                            $(document).ready(function () {
                                $('#delete-selected-action-confirmation-submit-button').bind('click', function () {
                                    var postData = {
                                        selectedIds: selectedIds
                                    };
                                    addAntiForgeryToken(postData);
                                    $.ajax({
                                        cache: false,
                                        type: "POST",
                                        url: "@(Url.Action("DeleteSelected", "Course"))",
                                        data: postData,
                                        error: function (jqXHR, textStatus, errorThrown) {
                                            $('#deleteSelectedFailed-info').text(errorThrown);
                                            $('#deleteSelectedFailed').click();
                                        },
                                        complete: function (jqXHR, textStatus) {
                                            updateTable('#courses-grid');
                                        }
                                    });
                                    $('#delete-selected-action-confirmation').modal('toggle');
                                    return false;
                                });
                            });

                            </script>
                            <nop-alert asp-alert-id="deleteSelectedFailed" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

</form>