const contentTableId = "#contentTable";


// region Init Module

function initContentModule() {
    initializeDataTable(
        contentTableId,
        [
            {
                title: "Subscription",
                data: "subscription"
            },
            {
                title: "Item ID",
                data: "item_id"
            },
            {
                title: "Item GUID",
                data: "item_guid"
            },
            {
                title: "Title",
                data: "item_title"
            },
            {
                title: "URL",
                data: "item_url"
            },
            {
                title: "Content Hash",
                data: "item_content_hash"
            }
        ]
    );
}


// region Load Data

$(document).on("selectedServerChange", async function() {
    await loadContentData();
});

$(contentTableId).on("doDataLoad", async function() {
    await loadContentData();
})

async function loadContentData() {
    if (!selectedServer){
        return;
    }

    setTableFilter(contentTableId, "subscription__server", selectedServer.id);
    await loadTableData(contentTableId, "/api/content/", "GET");
}