const getCookie = (name) => {
    if (typeof window === 'undefined')
        return;
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2)
        return parts.pop().split(';').shift();
};
const setCookie = (name, value, opts) => {
    if (typeof window === 'undefined')
        return;
    let expires = '';
    const { days, minutes, domain, path } = opts || {};
    if (opts === null || opts === void 0 ? void 0 : opts.expires) {
        expires = `; expires=${opts.expires}`;
    }
    else if (days || minutes) {
        const date = new Date();
        if (days) {
            date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
        }
        else {
            date.setTime(date.getTime() + minutes * 60 * 1000);
        }
        expires = '; expires=' + date.toUTCString();
    }
    document.cookie =
        name +
            '=' +
            (value || '') +
            expires +
            '; path=' +
            (path || '/') +
            (domain ? '; domain=' + domain : '');
};
const deleteCookie = (name) => {
    if (typeof window === 'undefined')
        return;
    document.cookie = name + '=; Max-Age=-99999999; path=/';
};

export { deleteCookie, getCookie, setCookie };
