import { DesignToken, FoundationElement } from '@ni/fast-foundation';
import { Observable } from '@ni/fast-element';
import { themeProviderTag } from '../../theme-provider';
/**
 * Base class for label providers
 */
export class LabelProviderBase extends FoundationElement {
    constructor() {
        super(...arguments);
        this.propertyNotifier = Observable.getNotifier(this);
    }
    connectedCallback() {
        super.connectedCallback();
        this.initializeThemeProvider();
        this.propertyNotifier.subscribe(this);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.propertyNotifier.unsubscribe(this);
        if (this.themeProvider) {
            for (const token of Object.values(this.supportedLabels)) {
                token.deleteValueFor(this.themeProvider);
            }
            this.themeProvider = undefined;
        }
    }
    handleChange(_element, property) {
        if (this.supportedLabels[property]) {
            const token = this.supportedLabels[property];
            const value = this[property];
            if (this.themeProvider) {
                if (value === null || value === undefined) {
                    token.deleteValueFor(this.themeProvider);
                }
                else {
                    token.setValueFor(this.themeProvider, value);
                }
            }
        }
    }
    initializeThemeProvider() {
        this.themeProvider = this.closest(themeProviderTag) ?? undefined;
        if (this.themeProvider) {
            for (const [property, token] of Object.entries(this.supportedLabels)) {
                const value = this[property];
                if (value === null || value === undefined) {
                    token.deleteValueFor(this.themeProvider);
                }
                else {
                    token.setValueFor(this.themeProvider, value);
                }
            }
        }
    }
}
//# sourceMappingURL=index.js.map