import { Disposable } from "../../../../base/common/lifecycle.mjs";
import { registerEditorContribution } from "../../../browser/editorExtensions.mjs";
import { Range } from "../../../common/core/range.mjs";
import { ColorDecorationInjectedTextMarker } from "./colorDetector.mjs";
import { ColorHoverParticipant } from "./colorHoverParticipant.mjs";
import { ModesHoverController } from "../../hover/browser/hover.mjs";
import { HoverParticipantRegistry } from "../../hover/browser/hoverTypes.mjs";
class ColorContribution extends Disposable {
  constructor(_editor) {
    super();
    this._editor = _editor;
    this._register(_editor.onMouseDown((e) => this.onMouseDown(e)));
  }
  dispose() {
    super.dispose();
  }
  onMouseDown(mouseEvent) {
    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(ModesHoverController.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, false);
    }
  }
}
ColorContribution.ID = "editor.contrib.colorContribution";
registerEditorContribution(ColorContribution.ID, ColorContribution);
HoverParticipantRegistry.register(ColorHoverParticipant);
export {
  ColorContribution
};
