// (C) 2026 GoodData Corporation
import { InvariantError } from "ts-invariant";
import { DefaultDashboardMeasureValueFilter } from "../../presentation/filterBar/measureValueFilter/DefaultDashboardMeasureValueFilter.js";
const DefaultMeasureValueFilterRendererProvider = () => {
    return DefaultDashboardMeasureValueFilter;
};
class DefaultMeasureValueFiltersCustomizerState {
    coreProviderChain;
    coreProvider = (measureValueFilter) => {
        const providerStack = [...this.coreProviderChain].reverse();
        for (const provider of providerStack) {
            const Component = provider(measureValueFilter);
            if (Component) {
                return Component;
            }
        }
        throw new InvariantError();
    };
    rootProvider = this.coreProvider;
    constructor(defaultProvider) {
        this.coreProviderChain = [defaultProvider];
    }
    addCustomProvider(provider) {
        this.coreProviderChain.push(provider);
    }
    getRootProvider() {
        return this.rootProvider;
    }
    switchRootProvider(provider) {
        this.rootProvider = provider;
    }
}
class SealedMeasureValueFiltersCustomizerState {
    logger;
    state;
    constructor(logger, state) {
        this.logger = logger;
        this.state = state;
    }
    addCustomProvider = (_provider) => {
        this.logger.warn(`Attempting to customize MeasureValueFilter rendering outside of plugin registration. Ignoring.`);
    };
    switchRootProvider = (_provider) => {
        this.logger.warn(`Attempting to customize MeasureValueFilter rendering outside of plugin registration. Ignoring.`);
    };
    getRootProvider = () => {
        return this.state.getRootProvider();
    };
}
/**
 * Default implementation of the MeasureValueFilter rendering customizer.
 *
 * @internal
 */
export class DefaultMeasureValueFiltersCustomizer {
    logger;
    state;
    constructor(logger, defaultProvider = DefaultMeasureValueFilterRendererProvider) {
        this.logger = logger;
        this.state = new DefaultMeasureValueFiltersCustomizerState(defaultProvider);
    }
    withCustomProvider = (provider) => {
        this.state.addCustomProvider(provider);
        return this;
    };
    getMeasureValueFilterProvider = () => {
        return this.state.getRootProvider();
    };
    sealCustomizer = () => {
        this.state = new SealedMeasureValueFiltersCustomizerState(this.logger, this.state);
    };
}
