import * as i18n from "../../core/i18n/i18n.js";
import * as Protocol from "../../generated/protocol.js";
import { Issue, IssueCategory, IssueKind } from "./Issue.js";
import { resolveLazyDescription } from "./MarkdownIssueDescription.js";
const UIStrings = {
  title: "Deprecated Feature Used",
  deprecationExample: "This is an example of a translated deprecation issue message."
};
const str_ = i18n.i18n.registerUIStrings("models/issues_manager/DeprecationIssue.ts", UIStrings);
const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(void 0, str_);
export class DeprecationIssue extends Issue {
  #issueDetails;
  constructor(issueDetails, issuesModel) {
    let typeCode = String(issueDetails.type);
    if (issueDetails.type === Protocol.Audits.DeprecationIssueType.Untranslated) {
      typeCode = String(issueDetails.deprecationType);
    }
    const issueCode = [
      Protocol.Audits.InspectorIssueCode.DeprecationIssue,
      typeCode
    ].join("::");
    super({ code: issueCode, umaCode: "DeprecationIssue" }, issuesModel);
    this.#issueDetails = issueDetails;
  }
  getCategory() {
    return IssueCategory.Other;
  }
  details() {
    return this.#issueDetails;
  }
  getDescription() {
    let messageFunction = () => "";
    switch (this.#issueDetails.type) {
      case Protocol.Audits.DeprecationIssueType.DeprecationExample:
        messageFunction = i18nLazyString(UIStrings.deprecationExample);
        break;
      case Protocol.Audits.DeprecationIssueType.Untranslated:
        messageFunction = () => this.#issueDetails.message ?? "";
        break;
    }
    return resolveLazyDescription({
      file: "deprecation.md",
      substitutions: /* @__PURE__ */ new Map([
        ["PLACEHOLDER_title", i18nLazyString(UIStrings.title)],
        ["PLACEHOLDER_message", messageFunction]
      ]),
      links: []
    });
  }
  sources() {
    if (this.#issueDetails.sourceCodeLocation) {
      return [this.#issueDetails.sourceCodeLocation];
    }
    return [];
  }
  primaryKey() {
    return JSON.stringify(this.#issueDetails);
  }
  getKind() {
    return IssueKind.BreakingChange;
  }
  static fromInspectorIssue(issuesModel, inspectorIssue) {
    const details = inspectorIssue.details.deprecationIssueDetails;
    if (!details) {
      console.warn("Deprecation issue without details received.");
      return [];
    }
    if (details.type !== Protocol.Audits.DeprecationIssueType.Untranslated && (details.deprecationType || details.message)) {
      console.warn("Translated deprecation issue with malformed details received.");
      return [];
    }
    if (details.type === Protocol.Audits.DeprecationIssueType.Untranslated && (!details.deprecationType || !details.message)) {
      console.warn("Untranslated deprecation issue with malformed details received.");
      return [];
    }
    return [new DeprecationIssue(details, issuesModel)];
  }
}
//# sourceMappingURL=DeprecationIssue.js.map
