// header function js

var HEADER = {};

HEADER.init = function() {
    $("#dspLoginId").text(ClientData.userInfo_loginId());

    $("#btnLogout").click(HEADER.logoutFunction);
};

HEADER.logoutFunction = function() {
    console.log("clicked logout");
    $("#msgModel").text(I18N.i18nText('msgLogoutConfirm'));

    $("#confirmYes").click(HEADER.processLogout);
}

HEADER.processLogout = function() {

    var params = {
        sid: ClientData.userInfo_sid()
    };
    const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.LOGOUT;
    COMMON.cmsAjax(url, params, false, 
                    function (data) {
                        if (data.httpStatus == CONSTANT.HTTP_STATUS.OK) {
                            SessionStorageUtils.clear();
                            COMMON.userSetting().remove(CONSTANT.KEYS.userInfo_sid);
                            COMMON.userSetting().remove(CONSTANT.KEYS.userInfo_sid_local);
                            // Move to login screen
                            //window.location = COMMON.ScreenIds.Login;
                            COMMON.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN);
                        } else {
                            if (data.errorMessage) {
                                COMMON.displayAlert(data.errorMessage);
                            } else {
                                COMMON.displayAlert("errorOccured");
                            }
                        }
                    },
                    function (xmlHttpRequest, txtStatus, errorThrown) {
                        if(xmlHttpRequest.errorMessage) {
                            COMMON.displayAlert(xmlHttpRequest.errorMessage);
                        } else {
                            COMMON.displayAlert("errorOccured");
                        }
                    });

}
