"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PHXFuncGetCookieSession;
const tslib_1 = require("tslib");
const constants_1 = require("../../utils/constants");
const helpers_1 = require("../../helpers/helpers");
const sessionStore_1 = require("./sessionStore");
const save_local_storage_1 = require("./save-local-storage");
const js_cookie_1 = tslib_1.__importDefault(require("js-cookie"));
function PHXFuncGetCookieSession() {
    const cachedSession = (0, sessionStore_1.getSession)();
    if (cachedSession)
        return cachedSession;
    if (typeof window === 'undefined')
        return null;
    try {
        let sessionInfo = null;
        const data = (0, save_local_storage_1.getLocalStorage)(constants_1.COOKIE_SESSION_SIGN_IN);
        if (data) {
            sessionInfo = JSON.parse(data);
        }
        if (!sessionInfo) {
            const cookieValue = js_cookie_1.default.get(constants_1.COOKIE_SESSION_SIGN_IN);
            if (cookieValue) {
                sessionInfo = cookieValue;
            }
        }
        if (!sessionInfo)
            return null;
        const sessionInfoDecrypt = (0, helpers_1.decryptCookie)(sessionInfo);
        if (!sessionInfoDecrypt)
            return null;
        (0, sessionStore_1.setSession)(sessionInfoDecrypt);
        return sessionInfoDecrypt;
    }
    catch (error) {
        console.warn('Session error:', error);
        return null;
    }
}
//# sourceMappingURL=getCookieSession.js.map