/*
    Created: 2025-02-27
    Author: Kārlis Grīnvalds
    Last edited: 2026-05-13
    Edited by: Kārlis Grīnvalds
*/

// Used for search.html

// Executes all the needed code
async function Load() {
    // Gets the url parameter
    const searched = decodeURI(window.location.href.split("?find=")[1]);
    await $.ajax({
        url: "/entry/find",
        method: "GET",
        data: {
            param: searched.toLowerCase(),
            topic: Topic()
        },
        success: function(response) {
            for (let _ = 0; _ < response.length; _++) {
                // If there are entries then it will output all in a table
                $("#SearchResults").append("<li><a href=\"/" + Topic() + "/" + response[_].name + "\">" + response[_].title + "</a></li>");
            }
            if (response.length <= 0) {
                // If nothing was found then this message will get shown
                $("#SearchResults").text("Couldn't find anything with \"" + searched + "\" related. :(");
            }
        },
        error: function(response) {
            // If there has been an error then it will show "Nothing found" message
            $("#SearchResults").text("Couldn't find anything with \"" + searched + "\" related. :(");
        }
    });
}