@model Nop.Web.Models.Catalog.SearchModel
@{
    Layout = "_ColumnsTwo";

    //title
    NopHtml.AddTitleParts(T("PageTitle.Search").Text);
    //page class
    NopHtml.AppendPageCssClassParts("html-search-page");
}
<script asp-location="Footer">
    $(function() {
        $("#@Html.IdFor(model => model.advs)").on('click', toggleAdvancedSearch);
        toggleAdvancedSearch();
    });

    function toggleAdvancedSearch() {
        if ($('#@Html.IdFor(model => model.advs)').is(':checked')) {
            $('#advanced-search-block').show();
        }
        else {
            $('#advanced-search-block').hide();
        }
    }
</script>
@section CatalogFilters {
    @await Html.PartialAsync("_CatalogFilters", Model.CatalogProductsModel)
}
<div class="page search-page">
    <div class="page-title panel-heading">
        <h1>@T("Search")</h1>
    </div>
    <div class="page-body">
        <div class="search-input form-horizontal">
            <form asp-route="ProductSearch" method="get">
                <div class="basic-search">
                    <div class="form-group">
                        <label class="control-label col-sm-2 col-md-2" asp-for="q">@T("Search.SearchTerm"):</label>
                        <div class="col-sm-6 col-md-6">
                            <input asp-for="q" class="search-text form-control" />
                        </div>
                    </div>
                    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductSearchPageBasic, additionalData = Model })
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-md-offset-2 col-sm-10 col-md-10">
                            <div class="checkbox">
                                <input asp-for="advs" />
                                <label asp-for="advs">@T("Search.AdvancedSearch")</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="advanced-search" id="advanced-search-block">
                    @if (Model.AvailableCategories.Count > 0)
                    {
                    <div class="form-group">
                        <label class="control-label col-sm-2 col-md-2" asp-for="cid">@T("Search.Category"):</label>
                        <div class="col-sm-6 col-md-6">
                            <select class="form-control dropdown-toggle category-iteam category-select" asp-for="cid" asp-items="Model.AvailableCategories"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-md-offset-2 col-sm-10 col-md-10">
                            <div class="checkbox">
                                <input asp-for="isc" />
                                <label asp-for="isc">@T("Search.IncludeSubCategories")</label>
                            </div>
                        </div>
                    </div>

                    }
                    @if (Model.AvailableManufacturers.Count > 0)
                    {
                    <div class="form-group">
                        <label class="control-label col-sm-2 col-md-2" asp-for="mid">@T("Search.Manufacturer"):</label>
                        <div class="col-sm-6 col-md-6">
                            <select class="form-control category-iteam dropdown-toggle" asp-for="mid" asp-items="Model.AvailableManufacturers"></select>
                        </div>
                    </div>
                    }
                    @if (Model.asv && Model.AvailableVendors.Count > 0)
                    {
                    <div class="form-group">
                        <label class="control-label col-sm-2 col-md-2" asp-for="vid">@T("Search.Vendor"):</label>
                        <div class="col-sm-6 col-md-6">
                            <select class="form-control" asp-for="vid" asp-items="Model.AvailableVendors"></select>
                        </div>
                    </div>
                    }
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-md-offset-2 col-sm-10 col-md-10">
                            <div class="checkbox">
                                <input asp-for="sid" />
                                <label asp-for="sid">@T("Search.SearchInDescriptions")</label>
                            </div>
                        </div>
                    </div>
                    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductSearchPageAdvanced, additionalData = Model })
                </div>
                <div class="form-group row">
                    <div class="col-sm-offset-2 col-md-offset-2 col-sm-2 col-md-2">
                        <button type="submit" class="btn btn-primary search-btn">@T("Search.Button")</button>
                    </div>
                </div>
            </form>
        </div>
        @await Html.PartialAsync("_CatalogSelectors", Model.CatalogProductsModel)
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductSearchPageBeforeResults, additionalData = Model })
        <div class="search-results">
            @{
                var catalogProductsViewData = new ViewDataDictionary(ViewData);
                catalogProductsViewData["fetchUrl"] = Html.Raw(Url.RouteUrl("SearchProducts"));
            }
            @await Html.PartialAsync("_CatalogProducts", Model.CatalogProductsModel, catalogProductsViewData)
            <script asp-location="Footer">
                $(function() {
                    $(CatalogProducts).on('before', function (e) {
                        var isAdvanced = $('#@Html.IdFor(model => model.advs)').is(':checked');

                        e.payload.urlBuilder
                            .addParameter('q', $('#@Html.IdFor(model => model.q)').val())
                            .addParameter('advs', isAdvanced);

                        if (isAdvanced) {
                            e.payload.urlBuilder
                                .addParameter('cid', $('#@Html.IdFor(model => model.cid)').val())
                                .addParameter('isc', $('#@Html.IdFor(model => model.isc)').is(':checked'))
                                .addParameter('mid', $('#@Html.IdFor(model => model.mid)').val())
                                .addParameter('vid', $('#@Html.IdFor(model => model.vid)').val())
                                .addParameter('sid', $('#@Html.IdFor(model => model.sid)').is(':checked'));
                        }
                    });
                });
            </script>
        </div>
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductSearchPageAfterResults, additionalData = Model })
    </div>
</div>
