import { typescriptWorkerFacet } from "./facet.js";
const typescriptHoverTooltips = async (view, pos) => {
  const { worker } = view.state.facet(typescriptWorkerFacet);
  const info = await worker.getHoverTooltip(pos);
  if (!info) return null;
  return {
    pos: info.start,
    end: info.end,
    above: true,
    create: () => {
      var _a, _b, _c, _d;
      const div = document.createElement("div");
      div.classList.add("cm-tooltip-lint");
      const wrapper = document.createElement("div");
      wrapper.classList.add("cm-diagnostic");
      div.appendChild(wrapper);
      const text = document.createElement("div");
      text.classList.add("cm-diagnosticText");
      wrapper.appendChild(text);
      if ((_a = info.quickInfo) == null ? void 0 : _a.displayParts) {
        for (const part of info.quickInfo.displayParts) {
          const span = text.appendChild(document.createElement("span"));
          if (part.kind === "keyword" && ["string", "number", "boolean", "object"].includes(part.text)) {
            span.className = "ts-primitive";
          } else if (part.kind === "punctuation" && ["(", ")"].includes(part.text)) {
            span.className = "ts-text";
          } else {
            span.className = `ts-${part.kind}`;
          }
          span.innerText = part.text;
        }
      }
      const documentation = (_d = (_c = (_b = info.quickInfo) == null ? void 0 : _b.documentation) == null ? void 0 : _c.find((doc) => doc.kind === "text")) == null ? void 0 : _d.text;
      if (documentation) {
        const docElement = document.createElement("div");
        docElement.classList.add("cm-diagnosticDocs");
        docElement.textContent = documentation;
        wrapper.appendChild(docElement);
      }
      return { dom: div };
    }
  };
};
export {
  typescriptHoverTooltips
};
//# sourceMappingURL=hover-tooltip.js.map
