function updateGuiOptionsState(modalName, key, value) {
    const state = getState();

    if (modalName === CONSENT_MODAL_NAME) {
        if (key === 'layout') {
            const layout = currentCMLayoutValue;
            const isBarLayout = layout.startsWith('bar');

            const consentModal = state._cookieConsentConfig.guiOptions.consentModal;
            const currentPosition = consentModal.position;

            if (validBarPositions(currentPosition)) {
                state._lastBarPosition = currentPosition;
            } else {
                state._lastNonBarPosition = currentPosition;
            }

            if (!isBarLayout && validBarPositions(currentPosition) || isBarLayout && !validBarPositions(currentPosition)) {
                generateCMPositionOptions(!isBarLayout);

                if (isBarLayout) {
                    if (!validBarPositions(currentPosition))
                        consentModal.position = htmlElements[CONSENT_MODAL_NAME].position.value = state._lastBarPosition || 'bottom';
                } else {
                    consentModal.position = htmlElements[CONSENT_MODAL_NAME].position.value = state._lastNonBarPosition || defaultConfig.guiOptions.consentModal.position;
                }
            }
        }

        if (key === 'position') {
            const currentPosition = state._cookieConsentConfig.guiOptions.consentModal.position;

            if (validBarPositions(currentPosition)) {
                state._lastBarPosition = currentPosition;
            } else {
                state._lastNonBarPosition = currentPosition;
            }
        }
    }else {
        if (key === 'layout') {
            if (currentPMLayoutValue === 'box')
                disablePMPositionOptions(true);
            else if (pmPositionOptionsDisabled)
                disablePMPositionOptions(false);
        }
    }

    state._cookieConsentConfig.guiOptions[modalName][key] = value;
    saveState(state);
    reRunPlugin(state, modalName === 'consentModal' ? 1 : 2);
}
@param {'consentModal' | 'preferencesModal'} modalName
@param {string} key
@param {any} value