import { Disposable } from '../../../../base/common/lifecycle.js';
import { registerEditorContribution } from '../../../browser/editorExtensions.js';
import { Range } from '../../../common/core/range.js';
import { ColorDecorationInjectedTextMarker } from './colorDetector.js';
import { ColorHoverParticipant } from './colorHoverParticipant.js';
import { HoverController } from '../../hover/browser/hover.js';
import { HoverParticipantRegistry } from '../../hover/browser/hoverTypes.js';
class ColorContribution extends Disposable {
    static { this.ID = 'editor.contrib.colorContribution'; }
    static { this.RECOMPUTE_TIME = 1000; }
    constructor(_editor) {
        super();
        this._editor = _editor;
        this._register(_editor.onMouseDown((e) => this.onMouseDown(e)));
    }
    dispose() {
        super.dispose();
    }
    onMouseDown(mouseEvent) {
        const colorDecoratorsActivatedOn = this._editor.getOption(148 );
        if (colorDecoratorsActivatedOn !== 'click' && colorDecoratorsActivatedOn !== 'clickAndHover') {
            return;
        }
        const target = mouseEvent.target;
        if (target.type !== 6 ) {
            return;
        }
        if (!target.detail.injectedText) {
            return;
        }
        if (target.detail.injectedText.options.attachedData !== ColorDecorationInjectedTextMarker) {
            return;
        }
        if (!target.range) {
            return;
        }
        const hoverController = this._editor.getContribution(HoverController.ID);
        if (!hoverController) {
            return;
        }
        if (!hoverController.isColorPickerVisible) {
            const range = ( new Range(
                target.range.startLineNumber,
                target.range.startColumn + 1,
                target.range.endLineNumber,
                target.range.endColumn + 1
            ));
            hoverController.showContentHover(range, 1 , 0 , false, true);
        }
    }
}
registerEditorContribution(ColorContribution.ID, ColorContribution, 2 );
HoverParticipantRegistry.register(ColorHoverParticipant);
export { ColorContribution };
