import { MatchDecorator, Decoration } from '@codemirror/view';
import { ChipWidget } from './ChipWidget.js';
/**
 * A class that specializes in creating and managing decorations for suggestion matches in a code editor.
 */
export class SuggestionMatchDecorator extends MatchDecorator {
    suggestions;
    /**
     * Creates a new instance of SuggestionMatchDecorator.
     * @param regexp - The regular expression used to match suggestions in the code.
     * @param suggestions - An array of suggestions that will be used to create decorations.
     * Each suggestion should have a unique `id` and a `label` that will be displayed in the editor.
     */
    constructor(regexp, suggestions) {
        super({
            regexp,
            decoration: (match) => this.#decoration(match),
        });
        this.suggestions = suggestions;
    }
    #decoration(match) {
        const id = match[1];
        const suggestion = this.suggestions.find((s) => s.id === id);
        // If no suggestion is found, create a default one
        const suggestionData = suggestion || { id, label: id };
        return Decoration.replace({
            widget: new ChipWidget(suggestionData),
        });
    }
}
//# sourceMappingURL=SuggestionMatchDecorator.js.map