"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const dom = require("../../dom.js");
const keyboardEvent = require("../../keyboardEvent.js");
const scrollableElement = require("../scrollbar/scrollableElement.js");
const lifecycle = require("../../../common/lifecycle.js");
require("./hover.css.js");
const $ = dom.$;
class HoverWidget extends lifecycle.Disposable {
  constructor() {
    super();
    this.containerDomNode = document.createElement("div");
    this.containerDomNode.className = "monaco-hover";
    this.containerDomNode.tabIndex = 0;
    this.containerDomNode.setAttribute("role", "tooltip");
    this.contentsDomNode = document.createElement("div");
    this.contentsDomNode.className = "monaco-hover-content";
    this.scrollbar = this._register(new scrollableElement.DomScrollableElement(this.contentsDomNode, {
      consumeMouseWheelIfScrollbarIsNeeded: true
    }));
    this.containerDomNode.appendChild(this.scrollbar.getDomNode());
  }
  onContentsChanged() {
    this.scrollbar.scanDomNode();
  }
}
class HoverAction extends lifecycle.Disposable {
  constructor(parent, actionOptions, keybindingLabel) {
    super();
    this.actionContainer = dom.append(parent, $("div.action-container"));
    this.actionContainer.setAttribute("tabindex", "0");
    this.action = dom.append(this.actionContainer, $("a.action"));
    this.action.setAttribute("role", "button");
    if (actionOptions.iconClass) {
      dom.append(this.action, $(`span.icon.${actionOptions.iconClass}`));
    }
    const label = dom.append(this.action, $("span"));
    label.textContent = keybindingLabel ? `${actionOptions.label} (${keybindingLabel})` : actionOptions.label;
    this._register(dom.addDisposableListener(this.actionContainer, dom.EventType.CLICK, (e) => {
      e.stopPropagation();
      e.preventDefault();
      actionOptions.run(this.actionContainer);
    }));
    this._register(dom.addDisposableListener(this.actionContainer, dom.EventType.KEY_UP, (e) => {
      const event = new keyboardEvent.StandardKeyboardEvent(e);
      if (event.equals(
        3
        /* Enter */
      )) {
        e.stopPropagation();
        e.preventDefault();
        actionOptions.run(this.actionContainer);
      }
    }));
    this.setEnabled(true);
  }
  static render(parent, actionOptions, keybindingLabel) {
    return new HoverAction(parent, actionOptions, keybindingLabel);
  }
  setEnabled(enabled) {
    if (enabled) {
      this.actionContainer.classList.remove("disabled");
      this.actionContainer.removeAttribute("aria-disabled");
    } else {
      this.actionContainer.classList.add("disabled");
      this.actionContainer.setAttribute("aria-disabled", "true");
    }
  }
}
exports.HoverAction = HoverAction;
exports.HoverWidget = HoverWidget;
