var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { RemixTooltip } from './widget/tooltip.js';
import { ChallengeBase } from '../challenge/base.js';
import { RemixDialogProvider } from './dialog.js';
import { debounce } from '../decorators.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.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.addStatusIcon();
        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(() => {
                if (this.tooltip) {
                    this.tooltip.dispose();
                }
                this.tooltip = null;
            });
        }
    }
    dispose() { }
}
__decorate([
    debounce(100)
], Remix.prototype, "selectSuggestion", null);
//# sourceMappingURL=remix.js.map