import { DOM } from '@ni/fast-element';
import { UpdateTracker } from '../../utilities/models/update-tracker';
const trackedItems = ['pattern', 'mappingConfigs', 'buttonLabel'];
/**
 * Helper class to track what updates are needed to the rich text components based on configuration
 * changes.
 */
export class RichTextUpdateTracker extends UpdateTracker {
    constructor(richText) {
        super(trackedItems);
        this.richText = richText;
        this.updateQueued = false;
    }
    get updatePattern() {
        return this.isTracked('pattern');
    }
    get updateMappingConfigs() {
        return this.isTracked('mappingConfigs');
    }
    get updateButtonLabel() {
        return this.isTracked('buttonLabel');
    }
    trackMentionInternalsPropertyChanged(changedMentionInternalsProperty) {
        switch (changedMentionInternalsProperty) {
            case 'mappingConfigs':
                this.track('mappingConfigs');
                break;
            case 'pattern':
                this.track('pattern');
                break;
            case 'buttonLabel':
                this.track('buttonLabel');
                break;
            default:
                break;
        }
        this.queueUpdate();
    }
    trackMentionElementsInstancesChanged() {
        this.track('pattern');
        this.track('mappingConfigs');
        this.track('buttonLabel');
        this.queueUpdate();
    }
    queueUpdate() {
        if (!this.richText.$fastController.isConnected) {
            return;
        }
        if (!this.updateQueued) {
            this.updateQueued = true;
            DOM.queueUpdate(() => {
                this.richText.createConfig();
                this.untrackAll();
                this.updateQueued = false;
            });
        }
    }
}
//# sourceMappingURL=rich-text-tracker.js.map