var CHK_MessageDetail = {};

msgMap.messageDetailTopTitle = {ja:"プッシュメッセージ詳細", ko:"Push Message Detail", en:"Push Message Detail"};
msgMap.messageDetailHeaderTitle = {ja:"メッセージ詳細", ko:"Message List", en:"Message Detail"};
msgMap.messageDetailContentTitle = {ja:"内容", ko:"Content", en:"Content"};
msgMap.messageDetailSendDateTitle = {ja:"日時", ko:"Send Date", en:"Send Date"};
msgMap.messageDetailWorkingNameTitle = {ja:"作業名", ko:"Working Name", en:"Working Name"};
msgMap.messageDetailSenderTitle = {ja:"送信者", ko:"Sender", en:"Sender"};

CHK_MessageDetail.init = function() {
    CHK.initCommon();
    $("#footer").load("main-footer.html", function() {
        CHK_Footer.activeDashboardBottomNav();
    });
    var urlParam = CHK.getUrlParameter();
    if (typeof urlParam !== 'object' || typeof urlParam.pushMessageId === 'undefined') {
		return;
	}
    let messageId = urlParam.pushMessageId;
    CHK.loadJson(CHK.jsonPath.pushMessageList, function (json) {
        var messageList = json.pushMessageList;
        if (typeof messageList !== 'object') {
            return;
        }
        for (var i = 0; i < messageList.length; i++) {
            let message = messageList[i];
            if (message.pushMessageId == messageId) {
                CHK_MessageDetail.showMessage(message);
                if (!message.readingFlg) {
                    //update reading flag
                    var param = {};
                    param.cmd = CHK.getCommand('actionPushMessage');
                    param.pushMessageId = messageId;
                    param.pushMessageAction = 'read';
                    CHK.sendABookCheckApi(param);
                }
                break;
            }
        }
    });
}

CHK_MessageDetail.showMessage = function(message) {
    $('#messageDetail #message').text(message.pushMessage);
    $('#messageDetail #sendDate').text(message.pushSendDate);
    $('#messageDetail #operationName').text(message.operationName);
    $('#messageDetail #sender').text(message.pushSendLoginId);
}

CHK_MessageDetail.goBack = function() {
    history.back();
}
