import { RemixTooltip } from './widget/tooltip.js';
import { ChallengeBase } from '../challenge/base.js';
import { RemixDialogProvider } from './dialog.js';
export class Remix extends ChallengeBase {
    constructor() {
        super(...arguments);
        this.tooltip = null;
    }
    start() {
        if (!this.editor.injected) {
            throw new Error('Could not start remix: The editor was not injected');
        }
        if (!this.data) {
            throw new Error('Could not start challenge: No data was provided');
        }
        this.dialog = this.editor.dialogs.registerDialog(new RemixDialogProvider(this.data));
        this.dialog.open();
        this.editor.load(this.data.app);
    }
    selectSuggestion(suggestion) {
        if (this.tooltip) {
            this.editor.removeContentWidget(this.tooltip);
            this.tooltip.dispose();
        }
        this.tooltip = new RemixTooltip();
        const target = this.editor.queryElement(suggestion.target);
        this.tooltip.setText(suggestion.content);
        this.tooltip.setPosition('bottom');
        this.tooltip.setOffset(0);
        this.tooltip.onDidDismiss(() => {
            this.deselectSuggestion();
        });
        this.editor.addContentWidget(this.tooltip);
        this.tooltip.setTarget(target);
    }
    deselectSuggestion() {
        if (this.tooltip) {
            this.tooltip.close()
                .then(() => {
                this.tooltip.dispose();
                this.tooltip = null;
            });
        }
    }
    dispose() { }
}
//# sourceMappingURL=remix.js.map