"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const dom = require("../../../../base/browser/dom.js");
const actionbar = require("../../../../base/browser/ui/actionbar/actionbar.js");
const actions = require("../../../../base/common/actions.js");
const codicons = require("../../../../base/common/codicons.js");
const color = require("../../../../base/common/color.js");
const event = require("../../../../base/common/event.js");
const objects = require("../../../../base/common/objects.js");
require("./media/peekViewWidget.css.js");
const editorExtensions = require("../../../browser/editorExtensions.js");
const codeEditorService = require("../../../browser/services/codeEditorService.js");
const embeddedCodeEditorWidget = require("../../../browser/widget/embeddedCodeEditorWidget.js");
const zoneWidget = require("../../zoneWidget/browser/zoneWidget.js");
const nls = require("../../../../nls.js");
const menuEntryActionViewItem = require("../../../../platform/actions/browser/menuEntryActionViewItem.js");
const contextkey = require("../../../../platform/contextkey/common/contextkey.js");
const extensions = require("../../../../platform/instantiation/common/extensions.js");
const instantiation = require("../../../../platform/instantiation/common/instantiation.js");
const colorRegistry = require("../../../../platform/theme/common/colorRegistry.js");
var __decorate = globalThis && globalThis.__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;
};
var __param = globalThis && globalThis.__param || function(paramIndex, decorator) {
  return function(target, key) {
    decorator(target, key, paramIndex);
  };
};
const IPeekViewService = instantiation.createDecorator("IPeekViewService");
extensions.registerSingleton(IPeekViewService, class {
  constructor() {
    this._widgets = /* @__PURE__ */ new Map();
  }
  addExclusiveWidget(editor, widget) {
    const existing = this._widgets.get(editor);
    if (existing) {
      existing.listener.dispose();
      existing.widget.dispose();
    }
    const remove = () => {
      const data = this._widgets.get(editor);
      if (data && data.widget === widget) {
        data.listener.dispose();
        this._widgets.delete(editor);
      }
    };
    this._widgets.set(editor, { widget, listener: widget.onDidClose(remove) });
  }
});
exports.PeekContext = void 0;
(function(PeekContext) {
  PeekContext.inPeekEditor = new contextkey.RawContextKey("inReferenceSearchEditor", true, nls.localize("inReferenceSearchEditor", "Whether the current code editor is embedded inside peek"));
  PeekContext.notInPeekEditor = PeekContext.inPeekEditor.toNegated();
})(exports.PeekContext || (exports.PeekContext = {}));
let PeekContextController = class PeekContextController2 {
  constructor(editor, contextKeyService) {
    if (editor instanceof embeddedCodeEditorWidget.EmbeddedCodeEditorWidget) {
      exports.PeekContext.inPeekEditor.bindTo(contextKeyService);
    }
  }
  dispose() {
  }
};
PeekContextController.ID = "editor.contrib.referenceController";
PeekContextController = __decorate([
  __param(1, contextkey.IContextKeyService)
], PeekContextController);
editorExtensions.registerEditorContribution(PeekContextController.ID, PeekContextController);
function getOuterEditor(accessor) {
  let editor = accessor.get(codeEditorService.ICodeEditorService).getFocusedCodeEditor();
  if (editor instanceof embeddedCodeEditorWidget.EmbeddedCodeEditorWidget) {
    return editor.getParentEditor();
  }
  return editor;
}
const defaultOptions = {
  headerBackgroundColor: color.Color.white,
  primaryHeadingColor: color.Color.fromHex("#333333"),
  secondaryHeadingColor: color.Color.fromHex("#6c6c6cb3")
};
exports.PeekViewWidget = class PeekViewWidget extends zoneWidget.ZoneWidget {
  constructor(editor, options, instantiationService) {
    super(editor, options);
    this.instantiationService = instantiationService;
    this._onDidClose = new event.Emitter();
    this.onDidClose = this._onDidClose.event;
    objects.mixin(this.options, defaultOptions, false);
  }
  dispose() {
    if (!this.disposed) {
      this.disposed = true;
      super.dispose();
      this._onDidClose.fire(this);
    }
  }
  style(styles) {
    let options = this.options;
    if (styles.headerBackgroundColor) {
      options.headerBackgroundColor = styles.headerBackgroundColor;
    }
    if (styles.primaryHeadingColor) {
      options.primaryHeadingColor = styles.primaryHeadingColor;
    }
    if (styles.secondaryHeadingColor) {
      options.secondaryHeadingColor = styles.secondaryHeadingColor;
    }
    super.style(styles);
  }
  _applyStyles() {
    super._applyStyles();
    let options = this.options;
    if (this._headElement && options.headerBackgroundColor) {
      this._headElement.style.backgroundColor = options.headerBackgroundColor.toString();
    }
    if (this._primaryHeading && options.primaryHeadingColor) {
      this._primaryHeading.style.color = options.primaryHeadingColor.toString();
    }
    if (this._secondaryHeading && options.secondaryHeadingColor) {
      this._secondaryHeading.style.color = options.secondaryHeadingColor.toString();
    }
    if (this._bodyElement && options.frameColor) {
      this._bodyElement.style.borderColor = options.frameColor.toString();
    }
  }
  _fillContainer(container) {
    this.setCssClass("peekview-widget");
    this._headElement = dom.$(".head");
    this._bodyElement = dom.$(".body");
    this._fillHead(this._headElement);
    this._fillBody(this._bodyElement);
    container.appendChild(this._headElement);
    container.appendChild(this._bodyElement);
  }
  _fillHead(container, noCloseAction) {
    const titleElement = dom.$(".peekview-title");
    if (this.options.supportOnTitleClick) {
      titleElement.classList.add("clickable");
      dom.addStandardDisposableListener(titleElement, "click", (event2) => this._onTitleClick(event2));
    }
    dom.append(this._headElement, titleElement);
    this._fillTitleIcon(titleElement);
    this._primaryHeading = dom.$("span.filename");
    this._secondaryHeading = dom.$("span.dirname");
    this._metaHeading = dom.$("span.meta");
    dom.append(titleElement, this._primaryHeading, this._secondaryHeading, this._metaHeading);
    const actionsContainer = dom.$(".peekview-actions");
    dom.append(this._headElement, actionsContainer);
    const actionBarOptions = this._getActionBarOptions();
    this._actionbarWidget = new actionbar.ActionBar(actionsContainer, actionBarOptions);
    this._disposables.add(this._actionbarWidget);
    if (!noCloseAction) {
      this._actionbarWidget.push(new actions.Action("peekview.close", nls.localize("label.close", "Close"), codicons.Codicon.close.classNames, true, () => {
        this.dispose();
        return Promise.resolve();
      }), { label: false, icon: true });
    }
  }
  _fillTitleIcon(container) {
  }
  _getActionBarOptions() {
    return {
      actionViewItemProvider: menuEntryActionViewItem.createActionViewItem.bind(void 0, this.instantiationService),
      orientation: 0
      /* HORIZONTAL */
    };
  }
  _onTitleClick(event2) {
  }
  setTitle(primaryHeading, secondaryHeading) {
    if (this._primaryHeading && this._secondaryHeading) {
      this._primaryHeading.innerText = primaryHeading;
      this._primaryHeading.setAttribute("title", primaryHeading);
      if (secondaryHeading) {
        this._secondaryHeading.innerText = secondaryHeading;
      } else {
        dom.clearNode(this._secondaryHeading);
      }
    }
  }
  setMetaTitle(value) {
    if (this._metaHeading) {
      if (value) {
        this._metaHeading.innerText = value;
        dom.show(this._metaHeading);
      } else {
        dom.hide(this._metaHeading);
      }
    }
  }
  _doLayout(heightInPixel, widthInPixel) {
    if (!this._isShowing && heightInPixel < 0) {
      this.dispose();
      return;
    }
    const headHeight = Math.ceil(this.editor.getOption(
      59
      /* lineHeight */
    ) * 1.2);
    const bodyHeight = Math.round(heightInPixel - (headHeight + 2));
    this._doLayoutHead(headHeight, widthInPixel);
    this._doLayoutBody(bodyHeight, widthInPixel);
  }
  _doLayoutHead(heightInPixel, widthInPixel) {
    if (this._headElement) {
      this._headElement.style.height = `${heightInPixel}px`;
      this._headElement.style.lineHeight = this._headElement.style.height;
    }
  }
  _doLayoutBody(heightInPixel, widthInPixel) {
    if (this._bodyElement) {
      this._bodyElement.style.height = `${heightInPixel}px`;
    }
  }
};
exports.PeekViewWidget = __decorate([
  __param(2, instantiation.IInstantiationService)
], exports.PeekViewWidget);
const peekViewTitleBackground = colorRegistry.registerColor("peekViewTitle.background", { dark: colorRegistry.transparent(colorRegistry.editorInfoForeground, 0.1), light: colorRegistry.transparent(colorRegistry.editorInfoForeground, 0.1), hc: null }, nls.localize("peekViewTitleBackground", "Background color of the peek view title area."));
const peekViewTitleForeground = colorRegistry.registerColor("peekViewTitleLabel.foreground", { dark: color.Color.white, light: color.Color.black, hc: color.Color.white }, nls.localize("peekViewTitleForeground", "Color of the peek view title."));
const peekViewTitleInfoForeground = colorRegistry.registerColor("peekViewTitleDescription.foreground", { dark: "#ccccccb3", light: "#616161", hc: "#FFFFFF99" }, nls.localize("peekViewTitleInfoForeground", "Color of the peek view title info."));
const peekViewBorder = colorRegistry.registerColor("peekView.border", { dark: colorRegistry.editorInfoForeground, light: colorRegistry.editorInfoForeground, hc: colorRegistry.contrastBorder }, nls.localize("peekViewBorder", "Color of the peek view borders and arrow."));
const peekViewResultsBackground = colorRegistry.registerColor("peekViewResult.background", { dark: "#252526", light: "#F3F3F3", hc: color.Color.black }, nls.localize("peekViewResultsBackground", "Background color of the peek view result list."));
colorRegistry.registerColor("peekViewResult.lineForeground", { dark: "#bbbbbb", light: "#646465", hc: color.Color.white }, nls.localize("peekViewResultsMatchForeground", "Foreground color for line nodes in the peek view result list."));
colorRegistry.registerColor("peekViewResult.fileForeground", { dark: color.Color.white, light: "#1E1E1E", hc: color.Color.white }, nls.localize("peekViewResultsFileForeground", "Foreground color for file nodes in the peek view result list."));
colorRegistry.registerColor("peekViewResult.selectionBackground", { dark: "#3399ff33", light: "#3399ff33", hc: null }, nls.localize("peekViewResultsSelectionBackground", "Background color of the selected entry in the peek view result list."));
colorRegistry.registerColor("peekViewResult.selectionForeground", { dark: color.Color.white, light: "#6C6C6C", hc: color.Color.white }, nls.localize("peekViewResultsSelectionForeground", "Foreground color of the selected entry in the peek view result list."));
const peekViewEditorBackground = colorRegistry.registerColor("peekViewEditor.background", { dark: "#001F33", light: "#F2F8FC", hc: color.Color.black }, nls.localize("peekViewEditorBackground", "Background color of the peek view editor."));
colorRegistry.registerColor("peekViewEditorGutter.background", { dark: peekViewEditorBackground, light: peekViewEditorBackground, hc: peekViewEditorBackground }, nls.localize("peekViewEditorGutterBackground", "Background color of the gutter in the peek view editor."));
colorRegistry.registerColor("peekViewResult.matchHighlightBackground", { dark: "#ea5c004d", light: "#ea5c004d", hc: null }, nls.localize("peekViewResultsMatchHighlight", "Match highlight color in the peek view result list."));
colorRegistry.registerColor("peekViewEditor.matchHighlightBackground", { dark: "#ff8f0099", light: "#f5d802de", hc: null }, nls.localize("peekViewEditorMatchHighlight", "Match highlight color in the peek view editor."));
colorRegistry.registerColor("peekViewEditor.matchHighlightBorder", { dark: null, light: null, hc: colorRegistry.activeContrastBorder }, nls.localize("peekViewEditorMatchHighlightBorder", "Match highlight border in the peek view editor."));
exports.IPeekViewService = IPeekViewService;
exports.getOuterEditor = getOuterEditor;
exports.peekViewBorder = peekViewBorder;
exports.peekViewEditorBackground = peekViewEditorBackground;
exports.peekViewResultsBackground = peekViewResultsBackground;
exports.peekViewTitleBackground = peekViewTitleBackground;
exports.peekViewTitleForeground = peekViewTitleForeground;
exports.peekViewTitleInfoForeground = peekViewTitleInfoForeground;
