autoclearCookiesHelper = (isFirstConsent) => {
    const state = globalObj._state;
    const allCookiesArray = getAllCookies();
    const categoriesToClear = getCategoriesWithCookies(isFirstConsent);

    /**
     * Clear cookies for each disabled service
     */
    for (const categoryName in state._lastChangedServices) {
        for (const serviceName of state._lastChangedServices[categoryName]) {
            const serviceCookies = state._allDefinedServices[categoryName][serviceName].cookies;
            const serviceIsDisabled = !elContains(state._acceptedServices[categoryName], serviceName);

            if (!serviceIsDisabled || !serviceCookies)
                continue;

            for (const cookieItem of serviceCookies) {
                const foundCookies = findMatchingCookies(allCookiesArray, cookieItem.name);
                eraseCookiesHelper(foundCookies, cookieItem.path, cookieItem.domain);
            }
        }
    }

    for (const currentCategoryName of categoriesToClear) {
        const category = state._allDefinedCategories[currentCategoryName];
        const autoClear = category.autoClear;
        const autoClearCookies = autoClear && autoClear.cookies || [];

        const categoryWasJustChanged = elContains(state._lastChangedCategoryNames, currentCategoryName);
        const categoryIsDisabled = !elContains(state._acceptedCategories, currentCategoryName);
        const categoryWasJustDisabled = categoryWasJustChanged && categoryIsDisabled;

        const shouldClearCookies = isFirstConsent
            ? categoryIsDisabled
            : categoryWasJustDisabled;

        if (!shouldClearCookies)
            continue;

        if (autoClear.reloadPage && categoryWasJustDisabled)
            state._reloadPage = true;

        for (const cookieItem of autoClearCookies) {
            const foundCookies = findMatchingCookies(allCookiesArray, cookieItem.name);
            eraseCookiesHelper(foundCookies, cookieItem.path, cookieItem.domain);
        }
    }
}
Delete all unused cookies
@param {boolean} [isFirstConsent]