<%# Search page for users %>
<%# ARGUMENTS: results - the results of the search, query - the last search %>

<%- include("../partials/header") -%>
<%- include("../partials/navigationPrivate") -%>

<h1 class="my-5 container display-2 text-center">Mutorials Search</h1>

<div class="jumbotron container">

    <div class="row">
        <%- include("../partials/components/search", { query }) -%>
    </div>
    
    <% if (results.length > 0) { %>
        <h3 class="mb-0 mt-4"><%= results.length %> results</h3>
        <% results.forEach((result) => { %>
            <a href="
                <%= result.type == 'QUESTION' ? '/question/'+result.id : (result.type == 'USER' ? '/profile/'+result.id : '#') %>
            " target="_blank" style="text-decoration: none;">
                <div class="d-block px-4 py-3 my-2 search-result bg-main">
                    <h4><span class="badge bg-secondary"><%= result.type %></span> <%= result.title %></h4>
                    <p class="mb-0"><%= result.preview %></p>
                </div>
            </a>
        <% }); %>

    <% } else if (query != "") { %>
        <div class="my-2 alert alert-danger">
            <p class="mb-1">No results found for your query:</p>
            <pre class="mb-0"><code><%= JSON.stringify(query, null, 2) %></code></pre>
        </div>
    <% } %>
    
</div>

<%- include("../partials/footer") -%>
