var PushMessageDetail = {};

PushMessageDetail.baseApiUrl = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.PUSH_MESSAGE_DETAIL;

/**
 * dummy json for test
 */
PushMessageDetail.dummyMessageDetailJson = {
    pushMessageId: 1,
    pushMessage: "内容が入ります。内容が入ります。内容が入ります。内容が入ります。",
    pushSendDate: "2022/07/06 14:14",
    operationName: "絞り検索",
    pushSendLoginId: "agentec"
}

/**
 * init when html loaded
 */
PushMessageDetail.init = function() {
    //load common html
    TEMPLATE.loadHearder("#includedHeader");
    const navs = [
        {
            titleLang: 'dashboard',
            href: 'dashboard.html',
        },
        {
            titleLang: 'messageListTitle',
            href: 'push-message-list.html',
        },
        {
            titleLang: 'messageDetail',
        },
    ];
    TEMPLATE.loadMainNavsTitle("#includedMainTitle", "messageDetail", navs, null);
    //request message detail data
    let urlParam = COMMON.getUrlParameter();
    if (typeof urlParam !== 'object' || typeof urlParam.pushMessageId === 'undefined') {
		return;
	}
    PushMessageDetail.getMessageDetail(urlParam.pushMessageId, function(message) {
        PushMessageDetail.showMessage(message);
    });
}

/**
 * request message data
 * @param {string} pushMessageId 
 * @param {object} callback 
 */
PushMessageDetail.getMessageDetail = function(pushMessageId, callback) {
    let param = {
        sid: COMMON.getSid(),
        pushMessageId: pushMessageId
    };
    const url = PushMessageDetail.baseApiUrl;
    COMMON.cmsAjax(url, param, true, function (json) {
        if (callback && json && json.pushMessage) {
            callback(json.pushMessage);
        }
    }, function() {
        console.log('PushMessageDetail.getMessageDetail error');
    });
}

/**
 * Show message data
 * @param {object} message 
 */
PushMessageDetail.showMessage = function(message) {
    $('#content').text(message.pushMessage);
    $('#sendDate').text(message.pushSendDate);
    $('#operationName').text(message.operationName);
    $('#sender').text(message.pushSendLoginId);
}
