import envData from '../../../../../config/env.json';

const { forumLocation } = envData;

export function getGuideUrl({ forumTopicId, title = '' }) {
  title = encodeURIComponent(title);
  return forumTopicId
    ? `${forumLocation}/t/${forumTopicId}`
    : `${forumLocation}/search?q=${title}%20in%3Atitle%20order%3Aviews`;
}

export function isGoodXHRStatus(status) {
  const statusInt = parseInt(status, 10);
  return (statusInt >= 200 && statusInt < 400) || statusInt === 402;
}

export function transformEditorLink(url) {
  return url
    .replace(
      /(?<=\/\/)(?<projectname>[^.]+)\.(?<username>[^.]+)\.repl\.co\/?/,
      'replit.com/@$<username>/$<projectname>'
    )
    .replace(
      /(?<=\/\/)(?<projectname>[^.]+)\.glitch\.me\/?/,
      'glitch.com/edit/#!/$<projectname>'
    );
}

@@ -548,35 +548,32 @@
 eplace(%0A      /(
-?%3C=
 %5C/%5C/)(?%3Cprojectn
@@ -625,16 +625,18 @@
 %0A      '
+//
 replit.c
@@ -699,11 +699,8 @@
   /(
-?%3C=
 %5C/%5C/
@@ -746,16 +746,18 @@
 %0A      '
+//
 glitch.c

replace lookbehind in transformEditorLink (#41889)