import dedent from 'dedent-js';

const formatOverallStats = (data, battletag, gameMode) => {
  const stats = data['stats'][gameMode]['overall_stats'];
  const moreStats = data['stats'][gameMode]['game_stats'];
  let level = stats['level'];
  let competitiveStats;

  if (typeof stats['prestige'] === 'number') {
    level += (stats['prestige'] * 100);
  }

  if (gameMode === 'competitive') {
    const winRate = ((stats['wins'] / stats['games']) * 100).toFixed(2);
    competitiveStats = dedent`
    \n- Losses: ${stats['losses'] || 0}
    - Ties: ${stats['ties'] || 0}
    - Win Rate: ${winRate || 0}%
    - Games: ${stats['games'] || 0}`;
  }

  return dedent`*${battletag}*'s Overall Stats:
  - Level: ${level || 0}
  - Rating: ${stats['comprank'] || 0}
  - Wins: ${stats['wins'] || 0}${competitiveStats || ''}
  - K/D Ratio: ${moreStats['kpd'] || 0}
  - Cards: ${moreStats['cards'] || 0}
  - Medals: ${moreStats['medals'] || 0}
  - Gold: ${moreStats['medals_gold'] || 0}
  - Silver: ${moreStats['medals_silver'] || 0}
  - Bronze: ${moreStats['medals_bronze'] || 0}`;
};

export default formatOverallStats;

@@ -24,16 +24,58 @@
 ent-js';
+%0Aimport %7B titlecase %7D from './formatText';
 %0A%0Aconst 
@@ -281,31 +281,49 @@
 ;%0A  let comp
-etitive
+GameStats;%0A  let compRank
 Stats;%0A%0A  if
@@ -442,24 +442,183 @@
 etitive') %7B%0A
+    const rank = stats%5B'tier'%5D ? titlecase(stats%5B'tier'%5D) : '-';%0A%0A    compRankStats = dedent%60%0A    %5Cn- Rating: $%7Bstats%5B'comprank'%5D %7C%7C 0%7D%0A    - Rank: $%7Brank%7D%60;%0A%0A
     const wi
@@ -678,24 +678,25 @@
 xed(2);%0A
+%0A
     comp
 etitiveS
@@ -683,30 +683,27 @@
 );%0A%0A    comp
-etitiv
+Gam
 eStats = ded
@@ -933,45 +933,29 @@
 %7C 0%7D
-%0A  - Rating: $%7Bstats%5B'
+$%7B
 comp
-rank'%5D
+RankStats
  %7C%7C 
-0
+''
 %7D%0A  
@@ -989,22 +989,19 @@
 0%7D$%7Bcomp
-etitiv
+Gam
 eStats %7C

Add rank to competitive stats