import Cookies from 'js-cookie';

export const Cookie = {
    setAccessToken(token: string) {
        const inOneDay = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
        Cookies.set('token', token, {
            secure: true,
            sameSite: 'lax',
            expires: inOneDay,
        });
    },
    getAccessToken() {
        return Cookies.get('token');
    },
    setRefreshToken(token: string) {
        const inOneMonth = new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000);
        Cookies.set('refresh_token', token, {
            secure: true,
            sameSite: 'lax',
            expires: inOneMonth,
        });
    },
    getRefreshToken() {
        return Cookies.get('refresh_token');
    },
    clearTokens() {
        Cookies.remove('token', {
            secure: true,
            sameSite: 'lax',
        });

        Cookies.remove('refresh_token', {
            secure: true,
            sameSite: 'lax',
        });
    },
};
