var exhibitionId = getUrlParam("id");
$(function () {
    $.ajax({
        type: "POST",
        url: "/manage_exhibitions/exhibits_with_orders",
        data: JSON.stringify({
            id: Number(exhibitionId)
        }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            content = ''
            for (let i = 0; i < data.exhibits.length; i++) {
                exhibit = data.exhibits[i];
                content += getExhibitItem(exhibit, exhibit.Number)
            }
            $('#exhibits-panel').html(content)
        },
        error: function (xhr, textStatus, error) {
            var msg = JSON.parse(xhr.responseText);
            alert(msg.error);
        }
    });
})

function back() {
    history.back();
}

function getExhibitItem(exhibit, number) {
    if (isImage(exhibit.Url)) {
        return `<div class="exhibit-panel" id="exhibit-panel">
        <div class="cover-frame">
            <img class="cover" id="cover" src="${exhibit.Url}">
        </div>
        <h2 class="number">#${number}</h2>
        <input class="view-btn" type="button" id="${exhibit.ID}&number=${number}" value="查看订单" onclick="viewOrders(this)">
    </div>`
    } else if (isVideo(exhibit.Url)) {
        return `<div class="exhibit-panel" id="exhibit-panel">
        <div class="cover-frame">
            <video class="cover" id="cover" src="${exhibit.Url}" controls></video>
        </div>
        <h2 class="number">#${number}</h2>
        <input class="view-btn" type="button" id="${exhibit.ID}&number=${number}" value="查看订单" onclick="viewOrders(this)">
    </div>`
    }
}

function viewOrders(btn) {
    window.location.assign("/view/html/orders.html?id=" + btn.id);
}