
import { DisposableStore } from '../../../base/common/lifecycle.js';
import '../../../base/common/observableInternal/index.js';
import { observableFromEventOpts } from '../../../base/common/observableInternal/observables/observableFromEvent.js';
import { derivedOpts } from '../../../base/common/observableInternal/observables/derived.js';

function observableConfigValue(key, defaultValue, configurationService) {
    function compute_$show2FramesUp() {
        return observableFromEventOpts({ debugName: () => `Configuration Key "${key}"`, }, (handleChange) => configurationService.onDidChangeConfiguration(e => {
            if (e.affectsConfiguration(key)) {
                handleChange(e);
            }
        }), () => configurationService.getValue(key) ?? defaultValue);
    }
    return compute_$show2FramesUp();
}
function bindContextKey(key, service, computeValue) {
    const boundKey = key.bindTo(service);
    function compute_$show2FramesUp() {
        const store = ( new DisposableStore());
        derivedOpts({ debugName: () => `Set Context Key "${key.key}"` }, reader => {
            const value = computeValue(reader);
            boundKey.set(value);
            return value;
        }).recomputeInitiallyAndOnChange(store);
        return store;
    }
    return compute_$show2FramesUp();
}

export { bindContextKey, observableConfigValue };
