var exhibitionId = getUrlParam("id");
$(function () {
    $.ajax({
        type: "POST",
        url: "/manage_exhibitions/visit_statistics",
        data: JSON.stringify({
            id: Number(exhibitionId)
        }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            let content = '';
            // 总数
            content = 
            `<h1>访问统计 (总量: ${data.count})</h1>
            <input class="back-btn" type="button" value="返回" onclick="back()">`
            $('#top-panel').html(content)
            content = 
            `<tr>
                <td>日期</td>
                <td>访问量</td>
            </tr>`
            for (let i = 0; i < data.visit_statistics.length; i++) {
                let visit = data.visit_statistics[i]
                content +=
                    `<tr>
                        <td>${getDate(visit.CreatedAt)}</td>
                        <td>${visit.Count}</td>
                    </tr>`
            }
            $('table').html(content)
        },
        error: function (xhr, textStatus, error) {
            var msg = JSON.parse(xhr.responseText);
            alert(msg.error);
        }
    });
})

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