"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const dom = require("../../../../../base/browser/dom.js");
const countBadge = require("../../../../../base/browser/ui/countBadge/countBadge.js");
const highlightedLabel = require("../../../../../base/browser/ui/highlightedlabel/highlightedLabel.js");
const iconLabel = require("../../../../../base/browser/ui/iconLabel/iconLabel.js");
const filters = require("../../../../../base/common/filters.js");
const labels = require("../../../../../base/common/labels.js");
const lifecycle = require("../../../../../base/common/lifecycle.js");
const resources = require("../../../../../base/common/resources.js");
const resolverService = require("../../../../common/services/resolverService.js");
const nls = require("../../../../../nls.js");
const instantiation = require("../../../../../platform/instantiation/common/instantiation.js");
const keybinding = require("../../../../../platform/keybinding/common/keybinding.js");
const label = require("../../../../../platform/label/common/label.js");
const styler = require("../../../../../platform/theme/common/styler.js");
const themeService = require("../../../../../platform/theme/common/themeService.js");
const referencesModel = require("../referencesModel.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);
  };
};
exports.DataSource = class DataSource {
  constructor(_resolverService) {
    this._resolverService = _resolverService;
  }
  hasChildren(element) {
    if (element instanceof referencesModel.ReferencesModel) {
      return true;
    }
    if (element instanceof referencesModel.FileReferences) {
      return true;
    }
    return false;
  }
  getChildren(element) {
    if (element instanceof referencesModel.ReferencesModel) {
      return element.groups;
    }
    if (element instanceof referencesModel.FileReferences) {
      return element.resolve(this._resolverService).then((val) => {
        return val.children;
      });
    }
    throw new Error("bad tree");
  }
};
exports.DataSource = __decorate([
  __param(0, resolverService.ITextModelService)
], exports.DataSource);
class Delegate {
  getHeight() {
    return 23;
  }
  getTemplateId(element) {
    if (element instanceof referencesModel.FileReferences) {
      return exports.FileReferencesRenderer.id;
    } else {
      return OneReferenceRenderer.id;
    }
  }
}
exports.StringRepresentationProvider = class StringRepresentationProvider {
  constructor(_keybindingService) {
    this._keybindingService = _keybindingService;
  }
  getKeyboardNavigationLabel(element) {
    var _a;
    if (element instanceof referencesModel.OneReference) {
      const parts = (_a = element.parent.getPreview(element)) === null || _a === void 0 ? void 0 : _a.preview(element.range);
      if (parts) {
        return parts.value;
      }
    }
    return resources.basename(element.uri);
  }
};
exports.StringRepresentationProvider = __decorate([
  __param(0, keybinding.IKeybindingService)
], exports.StringRepresentationProvider);
class IdentityProvider {
  getId(element) {
    return element instanceof referencesModel.OneReference ? element.id : element.uri;
  }
}
let FileReferencesTemplate = class FileReferencesTemplate2 extends lifecycle.Disposable {
  constructor(container, _uriLabel, themeService2) {
    super();
    this._uriLabel = _uriLabel;
    const parent = document.createElement("div");
    parent.classList.add("reference-file");
    this.file = this._register(new iconLabel.IconLabel(parent, { supportHighlights: true }));
    this.badge = new countBadge.CountBadge(dom.append(parent, dom.$(".count")));
    this._register(styler.attachBadgeStyler(this.badge, themeService2));
    container.appendChild(parent);
  }
  set(element, matches) {
    let parent = resources.dirname(element.uri);
    this.file.setLabel(labels.getBaseLabel(element.uri), this._uriLabel.getUriLabel(parent, { relative: true }), { title: this._uriLabel.getUriLabel(element.uri), matches });
    const len = element.children.length;
    this.badge.setCount(len);
    if (len > 1) {
      this.badge.setTitleFormat(nls.localize("referencesCount", "{0} references", len));
    } else {
      this.badge.setTitleFormat(nls.localize("referenceCount", "{0} reference", len));
    }
  }
};
FileReferencesTemplate = __decorate([
  __param(1, label.ILabelService),
  __param(2, themeService.IThemeService)
], FileReferencesTemplate);
exports.FileReferencesRenderer = class FileReferencesRenderer {
  constructor(_instantiationService) {
    this._instantiationService = _instantiationService;
    this.templateId = FileReferencesRenderer.id;
  }
  renderTemplate(container) {
    return this._instantiationService.createInstance(FileReferencesTemplate, container);
  }
  renderElement(node, index, template) {
    template.set(node.element, filters.createMatches(node.filterData));
  }
  disposeTemplate(templateData) {
    templateData.dispose();
  }
};
exports.FileReferencesRenderer.id = "FileReferencesRenderer";
exports.FileReferencesRenderer = __decorate([
  __param(0, instantiation.IInstantiationService)
], exports.FileReferencesRenderer);
class OneReferenceTemplate {
  constructor(container) {
    this.label = new highlightedLabel.HighlightedLabel(container);
  }
  set(element, score) {
    var _a;
    const preview = (_a = element.parent.getPreview(element)) === null || _a === void 0 ? void 0 : _a.preview(element.range);
    if (!preview || !preview.value) {
      this.label.set(`${resources.basename(element.uri)}:${element.range.startLineNumber + 1}:${element.range.startColumn + 1}`);
    } else {
      const { value, highlight } = preview;
      if (score && !filters.FuzzyScore.isDefault(score)) {
        this.label.element.classList.toggle("referenceMatch", false);
        this.label.set(value, filters.createMatches(score));
      } else {
        this.label.element.classList.toggle("referenceMatch", true);
        this.label.set(value, [highlight]);
      }
    }
  }
}
class OneReferenceRenderer {
  constructor() {
    this.templateId = OneReferenceRenderer.id;
  }
  renderTemplate(container) {
    return new OneReferenceTemplate(container);
  }
  renderElement(node, index, templateData) {
    templateData.set(node.element, node.filterData);
  }
  disposeTemplate() {
  }
}
OneReferenceRenderer.id = "OneReferenceRenderer";
class AccessibilityProvider {
  getWidgetAriaLabel() {
    return nls.localize("treeAriaLabel", "References");
  }
  getAriaLabel(element) {
    return element.ariaMessage;
  }
}
exports.AccessibilityProvider = AccessibilityProvider;
exports.Delegate = Delegate;
exports.IdentityProvider = IdentityProvider;
exports.OneReferenceRenderer = OneReferenceRenderer;
