// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/*
  To use links in markdown, add key here with the link and
  use the added key in markdown.
  @example markdown
  Find more information about web development at [Learn more](exampleLink)
*/

// This is only exported for tests, and it should not be
// imported in any component, instead add link in map and
// use getMarkdownLink to get the appropriate link.
export const markdownLinks = new Map<string, string>([
  ['issuesContrastWCAG21AA', 'https://www.w3.org/TR/WCAG21/#contrast-minimum'],
  ['issuesContrastWCAG21AAA', 'https://www.w3.org/TR/WCAG21/#contrast-enhanced'],
  ['issuesContrastSuggestColor', 'https://developers.google.com/web/updates/2020/08/devtools#accessible-color'],
  ['issuesCSPSetStrict', 'https://web.dev/strict-csp'],
  [
    'issuesCSPWhyStrictOverAllowlist',
    'https://web.dev/strict-csp/#why-a-strict-csp-is-recommended-over-allowlist-csps',
  ],
  [
    'issueCorsPreflightRequest',
    'https://web.dev/cross-origin-resource-sharing/#preflight-requests-for-complex-http-calls',
  ],
  ['issueQuirksModeDoctype', 'https://web.dev/doctype/'],
  ['sameSiteAndSameOrigin', 'https://web.dev/same-site-same-origin/'],
]);

export const getMarkdownLink = (key: string): string => {
  const link = markdownLinks.get(key);
  if (!link) {
    throw new Error(`Markdown link with key '${key}' is not available, please check MarkdownLinksMap.ts`);
  }
  return link;
};
