import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { DisposableStore } from '../../../../base/common/lifecycle.js';
import '../../../../base/common/arrays.js';
import '../../../../base/common/observableInternal/derived.js';
import '../../../../base/common/observableInternal/autorun.js';
import { constObservable } from '../../../../base/common/observableInternal/utils.js';
import '../../../../base/common/cancellation.js';
import { MouseTargetType } from '../../../browser/editorBrowser.js';
import { EditorOption } from '../../../common/config/editorOptions.js';
import { HoverForeignElementAnchor, RenderedHoverParts, HoverAnchorType } from '../../hover/browser/hoverTypes.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.service.js';
import { InlineEditController } from './inlineEditController.js';
import { InlineEditHintsContentWidget } from './inlineEditHintsWidget.js';
import { localizeWithPath } from '../../../../nls.js';
const _moduleId = "vs/editor/contrib/inlineEdit/browser/hoverParticipant";
class InlineEditHover {
    constructor(owner, range, controller) {
        this.owner = owner;
        this.range = range;
        this.controller = controller;
    }
    isValidForHoverAnchor(anchor) {
        return (anchor.type === HoverAnchorType.Range
            && this.range.startColumn <= anchor.range.startColumn
            && this.range.endColumn >= anchor.range.endColumn);
    }
}
let InlineEditHoverParticipant = class InlineEditHoverParticipant {
    constructor(_editor, _instantiationService, _telemetryService) {
        this._editor = _editor;
        this._instantiationService = _instantiationService;
        this._telemetryService = _telemetryService;
        this.hoverOrdinal = 5;
    }
    suggestHoverAnchor(mouseEvent) {
        const controller = InlineEditController.get(this._editor);
        if (!controller) {
            return null;
        }
        const target = mouseEvent.target;
        if (target.type === MouseTargetType.CONTENT_VIEW_ZONE) {
            const viewZoneData = target.detail;
            if (controller.shouldShowHoverAtViewZone(viewZoneData.viewZoneId)) {
                const range = target.range;
                return (
                     (new HoverForeignElementAnchor(1000, this, range, mouseEvent.event.posx, mouseEvent.event.posy, false))
                );
            }
        }
        if (target.type === MouseTargetType.CONTENT_EMPTY) {
            if (controller.shouldShowHoverAt(target.range)) {
                return (
                     (new HoverForeignElementAnchor(
                        1000,
                        this,
                        target.range,
                        mouseEvent.event.posx,
                        mouseEvent.event.posy,
                        false
                    ))
                );
            }
        }
        if (target.type === MouseTargetType.CONTENT_TEXT) {
            const mightBeForeignElement = target.detail.mightBeForeignElement;
            if (mightBeForeignElement && controller.shouldShowHoverAt(target.range)) {
                return (
                     (new HoverForeignElementAnchor(
                        1000,
                        this,
                        target.range,
                        mouseEvent.event.posx,
                        mouseEvent.event.posy,
                        false
                    ))
                );
            }
        }
        return null;
    }
    computeSync(anchor, lineDecorations) {
        if (this._editor.getOption(EditorOption.inlineEdit).showToolbar !== 'onHover') {
            return [];
        }
        const controller = InlineEditController.get(this._editor);
        if (controller && controller.shouldShowHoverAt(anchor.range)) {
            return [( (new InlineEditHover(this, anchor.range, controller)))];
        }
        return [];
    }
    renderHoverParts(context, hoverParts) {
        const disposables = ( (new DisposableStore()));
        this._telemetryService.publicLog2('inlineEditHover.shown');
        const w = this._instantiationService.createInstance(InlineEditHintsContentWidget, this._editor, false, constObservable(null));
        disposables.add(w);
        const widgetNode = w.getDomNode();
        const renderedHoverPart = {
            hoverPart: hoverParts[0],
            hoverElement: widgetNode,
            dispose: () => disposables.dispose()
        };
        return (
             (new RenderedHoverParts([renderedHoverPart]))
        );
    }
    getAccessibleContent(hoverPart) {
        return ( localizeWithPath(_moduleId, 0, 'There are inline edits here.'));
    }
};
InlineEditHoverParticipant = ( (__decorate([
    ( (__param(1, IInstantiationService))),
    ( (__param(2, ITelemetryService)))
], InlineEditHoverParticipant)));
export { InlineEditHover, InlineEditHoverParticipant };
