import add from '../support/task';
import addStatTotalToMouseover from '../common/addStatTotalToMouseover';
import ajaxifyProfileSections from './ajaxifyProfileSections';
// import {closestForm} from '../common/closest';
import colouredDots from '../common/colouredDots';
import components from './components/components';
// import dontPost from '../common/dontPost';
import fallback from '../system/fallback';
import fastDebuff from './debuff';
import getElementsByTagName from '../common/getElementsByTagName';
import getText from '../common/getText';
import getUrlParameter from '../system/getUrlParameter';
import highlightPvpProtection from './highlightPvpProtection';
import injectFastWear from './fastWear';
import jQueryNotPresent from '../common/jQueryNotPresent';
import nekidBtn from './nekidBtn';
// import on from '../common/on';
import {pCC} from '../support/layout';
import playerId from '../common/playerId';
import playerName from '../common/playerName';
import {profileInjectGuildRel} from './profileInjectGuildRel';
import profileInjectQuickButton from './profileInjectQuickButton';
import profileParseAllyEnemy from './profileAllyEnemy';
import profileRenderBio from './bio/bio';
import querySelector from '../common/querySelector';
import quickWearLink from './quickWearLink';
import selectAllLink from './selectAllLink';
import storeVL from './storeVL';
import updateNmv from './updateNmv';
import updateStatistics from './updateStatistics';

function ifSelf(self) {
  if (self) {
    // self inventory
    fastDebuff();
    profileParseAllyEnemy();
    injectFastWear();
    components();
    quickWearLink();
    selectAllLink();
    storeVL();
    nekidBtn();
    ajaxifyProfileSections();
  }
}

function guildRelationship(avyImg, playername, self) {
  // Must be before profileInjectQuickButton
  profileInjectGuildRel(self);
  // It sets up guildId and currentGuildRelationship
  var playerid = fallback(getUrlParameter('player_id'), playerId());
  profileInjectQuickButton(avyImg, playerid, playername);
}

function updateDom(avyImg, playername, self) {
  ifSelf(self);
  guildRelationship(avyImg, playername, self);
  updateNmv();
  updateStatistics();
  highlightPvpProtection();
  add(3, profileRenderBio, [self]);
  addStatTotalToMouseover();
  add(3, colouredDots);
}

// function updateUrl(e) {
//   e.preventDefault();
//   dontPost(closestForm(e.target).parentNode);
// }

// function allowBack(self) {
//   if (!self) {
//     on(querySelector('#profileRightColumn'), 'submit', updateUrl);
//   }
// }

export default function injectProfile() { // Legacy
  if (jQueryNotPresent()) {return;}
  var avyImg = querySelector('#profileLeftColumn img[oldtitle*="\'s Avatar"]');
  if (!avyImg) {return;}
  var playername = getText(getElementsByTagName('h1', pCC)[0]);
  var self = playername === playerName();
  updateDom(avyImg, playername, self);
  // allowBack(self);
}

@@ -170,55 +170,88 @@
 ;%0A//
- import %7BclosestForm%7D from '../common/closest';
+#if _DEV  //  allow back%0Aimport %7BarrayFrom%7D from '../common/arrayFrom';%0A//#endif
 %0Aimp
@@ -352,54 +352,8 @@
 s';%0A
-// import dontPost from '../common/dontPost';%0A
 impo
@@ -650,24 +650,107 @@
 rotection';%0A
+//#if _DEV  //  allow back%0Aimport %7BindexPhp%7D from '../support/constants';%0A//#endif%0A
 import injec
@@ -874,17 +874,41 @@
 Btn';%0A//
- 
+#if _DEV  //  allow back%0A
 import o
@@ -926,24 +926,33 @@
 common/on';%0A
+//#endif%0A
 import %7BpCC%7D
@@ -2398,20 +2398,44 @@
 ots);%0A%7D%0A
-%0A// 
+//#if _DEV  //  allow back%0A%0A
 function
@@ -2450,19 +2450,16 @@
 rl(e) %7B%0A
-// 
   e.prev
@@ -2476,66 +2476,213 @@
 ();%0A
-//   dontPost(closestForm(e.target).parentNode);%0A// %7D%0A%0A// 
+  var validInputs = arrayFrom(e.target.closest('form').elements)%0A    .filter(i =%3E i.type !== 'submit')%0A    .map(i =%3E i.name + '=' + i.value).join('&');%0A  window.location = indexPhp + '?' + validInputs;%0A%7D%0A%0A
 func
@@ -2704,19 +2704,16 @@
 self) %7B%0A
-// 
   if (!s
@@ -2723,15 +2723,12 @@
 ) %7B%0A
-//
     
- 
 on(q
@@ -2790,19 +2790,22 @@
 l);%0A
-//   %7D%0A// %7D
+  %7D%0A%7D%0A//#endif
 %0A%0Aex
@@ -3144,16 +3144,42 @@
 f);%0A  //
+#if _DEV  //  allow back%0A 
  allowBa
@@ -3188,10 +3188,21 @@
 (self);%0A
+  //#endif%0A
 %7D%0A

allow back in profile view attack