import { COOKIE_SESSION_SIGN_IN } from '../../utils/constants';
import { decryptCookie } from '../../helpers/helpers';
import { getSession, setSession } from './sessionStore';
import { getLocalStorage } from './save-local-storage';
import Cookies from 'js-cookie';
export default function PHXFuncGetCookieSession() {
    const cachedSession = getSession();
    if (cachedSession)
        return cachedSession;
    if (typeof window === 'undefined')
        return null;
    try {
        let sessionInfo = null;
        const data = getLocalStorage(COOKIE_SESSION_SIGN_IN);
        if (data) {
            sessionInfo = JSON.parse(data);
        }
        if (!sessionInfo) {
            const cookieValue = Cookies.get(COOKIE_SESSION_SIGN_IN);
            if (cookieValue) {
                sessionInfo = cookieValue;
            }
        }
        if (!sessionInfo)
            return null;
        const sessionInfoDecrypt = decryptCookie(sessionInfo);
        if (!sessionInfoDecrypt)
            return null;
        setSession(sessionInfoDecrypt);
        return sessionInfoDecrypt;
    }
    catch (error) {
        console.warn('Session error:', error);
        return null;
    }
}
//# sourceMappingURL=getCookieSession.js.map