var linkURLs = [];

function sendToAirtable(name, username, link, insta) {
  var settings = {
    url:
      "https://api.airtable.com/v0/apprAqv7bCUXpgnbI/newjerseys?maxRecords=3",
    method: "POST",
    timeout: 0,
    headers: {
      Authorization: "Bearer keyyMakxKW8l2pvdX",
      "Content-Type": "application/json",
      Cookie: "brw=brw8HMZKbbvtlzwQU"
    },
    data: JSON.stringify({
      records: [
        {
          fields: {
            Name: name,
            "Link To Image": link,
            Image: [
              {
                url: link
              }
            ],
            Username: username,
            TwitterImage: [
              {
                url: link
              }
            ],
            InstaImage: [
              {
                url: insta
              }
            ]
          }
        }
      ]
    })
  };

  $.ajax(settings).done(function (response) {
    console.log(response);
  });
}

function embedTheFont(stid) {
  var embeds = document.getElementsByClassName(stid);
  for (var e = 0; e < embeds.length; e++) {
    embeds[e].innerHTML = `@font-face {
              font-family: 'abolitionregular';
              src: url("data:font/woff;charset=utf-8;base64,d09GRgABAAAAACmsABAAAAAAZ8wAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABbAAAABwAAAAcfIkonUdERUYAAAGIAAAAHQAAAB4AJwEGR1BPUwAAAagAAAchAAAVpAPp/g5HU1VCAAAIzAAAAaAAAANu1PyFn09TLzIAAApsAAAATAAAAGBo844fY21hcAAACrgAAAHEAAACMh7vjtRnYXNwAAAMfAAAAAgAAAAI//8AA2dseWYAAAyEAAAU3wAAPOBt17oPaGVhZAAAIWQAAAA2AAAANgiD1+ZoaGVhAAAhnAAAACEAAAAkByoDeGhtdHgAACHAAAABxQAABABJGxgAbG9jYQAAI4gAAAH7AAACAjhjKTptYXhwAAAlhAAAAB0AAAAgAUkAO25hbWUAACWkAAABiAAAA0orGHtfcG9zdAAAJywAAAJ4AAAEIN5/pS13ZWJmAAAppAAAAAYAAAAGz/dalAAAAAEAAAAA1e6U9QAAAADP4BMzAAAAANa6gHR42mNgZGBg4AFiMSBmYmAEwv9AzALmMQAADpMBLgAAAHjarVhraBxVFP5ms9kkm2Q3r93NqzZ9GKUg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Y2OeTSnR70pBd55FOAg8J/7t70oS/96M8ABjKIwQxhKMMYzgicFDOSUYxmDGMZh4vxTGAikyhhMqWUUU4FU5jKNKYzg5nMYjZzmMs85rMAjaNsZBP72cxudnCA42znPRvYxVZu8ZGDnOAIp3jAPU5TiZu9eHiEl/s85BmPecJTvlLFS57zgjP42McbXvGahXznJ9tYhM5iAvgJcohqaqnBwCREHUtYyjfqWc4yVrCKlVzlMGtYzVrW8YNfXOMs5/jMF65zjLd84gPvOM8FLnOF21zkEndYzxZOcpcb3JQoacZOfrNHoqW52CRGWkhLiRW7tJLWEifxkiBtJFHaSjtpL0mSLCnSQTpKqqRJumRIpmRJJ+ksXaSrdJNsyZFc6S49pKf0kjzJlwJxSKEUxYSCepGj96jo0SGjOnzpO2akzZlvmo5Cu1Nzh+q84fcEp1s33KFAld9bHw7inB7da3hN3Yx0fYa2RHVjnYYe9EXiOt3vUbGtWGGcgksVXBaHq6nD1djhanDYJimUqC8lFk2pQplCuUKF6lW4NaM6qCJNRZplAK3pAFrjATTLklrDkprFXqmwUEFXBd3i0Js69MYO3bJkQEENbA9aNDUKtQqGQuQPZsOS8T6vEdCCnkq/GVkoUOM1zH9J+PoXupn/XAABWpTP9gAA") format('woff');
font-weight: normal;
              font-style: normal;
            }`;
  }
}

function chgOutline(color) {
  var tempOls = document.getElementsByClassName("chgOutline")
  for (var t=0; t<tempOls.length; t++){
    tempOls[t].style.stroke = color;
  }
}

function chgStitching(color) {
  var tempStitch = document.getElementsByClassName("chgStitch")
  for (var t=0; t<tempStitch.length; t++){
    tempStitch[t].style.stroke = color;
  }
}

function chgFill(color) {
  var tempFills = document.getElementsByClassName("chgFill");
  for (var t=0; t<tempFills.length; t++){
    tempFills[t].style.fill = color;
  }
}

const pSBC = (p, c0, c1, l) => {
  let r,
    g,
    b,
    P,
    f,
    t,
    h,
    i = parseInt,
    m = Math.round,
    a = typeof c1 == "string";
  if (
    typeof p != "number" ||
    p < -1 ||
    p > 1 ||
    typeof c0 != "string" ||
    (c0[0] != "r" && c0[0] != "#") ||
    (c1 && !a)
  )
    return null;
  if (!this.pSBCr)
    this.pSBCr = (d) => {
      let n = d.length,
        x = {};
      if (n > 9) {
        ([r, g, b, a] = d = d.split(",")), (n = d.length);
        if (n < 3 || n > 4) return null;
        (x.r = i(r[3] == "a" ? r.slice(5) : r.slice(4))),
          (x.g = i(g)),
          (x.b = i(b)),
          (x.a = a ? parseFloat(a) : -1);
      } else {
        if (n == 8 || n == 6 || n < 4) return null;
        if (n < 6)
          d =
            "#" +
            d[1] +
            d[1] +
            d[2] +
            d[2] +
            d[3] +
            d[3] +
            (n > 4 ? d[4] + d[4] : "");
        d = i(d.slice(1), 16);
        if (n == 9 || n == 5)
          (x.r = (d >> 24) & 255),
            (x.g = (d >> 16) & 255),
            (x.b = (d >> 8) & 255),
            (x.a = m((d & 255) / 0.255) / 1000);
        else
          (x.r = d >> 16), (x.g = (d >> 8) & 255), (x.b = d & 255), (x.a = -1);
      }
      return x;
    };
  (h = c0.length > 9),
    (h = a ? (c1.length > 9 ? true : c1 == "c" ? !h : false) : h),
    (f = this.pSBCr(c0)),
    (P = p < 0),
    (t =
      c1 && c1 != "c"
        ? this.pSBCr(c1)
        : P
        ? { r: 0, g: 0, b: 0, a: -1 }
        : { r: 255, g: 255, b: 255, a: -1 }),
    (p = P ? p * -1 : p),
    (P = 1 - p);
  if (!f || !t) return null;
  if (l)
    (r = m(P * f.r + p * t.r)),
      (g = m(P * f.g + p * t.g)),
      (b = m(P * f.b + p * t.b));
  else
    (r = m((P * f.r ** 2 + p * t.r ** 2) ** 0.5)),
      (g = m((P * f.g ** 2 + p * t.g ** 2) ** 0.5)),
      (b = m((P * f.b ** 2 + p * t.b ** 2) ** 0.5));
  (a = f.a),
    (t = t.a),
    (f = a >= 0 || t >= 0),
    (a = f ? (a < 0 ? t : t < 0 ? a : a * P + t * p) : 0);
  if (h)
    return (
      "rgb" +
      (f ? "a(" : "(") +
      r +
      "," +
      g +
      "," +
      b +
      (f ? "," + m(a * 1000) / 1000 : "") +
      ")"
    );
  else
    return (
      "#" +
      (4294967296 + r * 16777216 + g * 65536 + b * 256 + (f ? m(a * 255) : 0))
        .toString(16)
        .slice(1, f ? undefined : -2)
    );
};

function chgMesh(color) {
  var elems = document.getElementsByTagName("ellipse");
  for (var i = 0; i < elems.length; i++) {
    elems[i].style.fill = color;
  }
}

function chgJerseyColor(color) {
  var jerseys = document.getElementsByClassName("jerseyChg");
  for(var j =0; j<jerseys.length; j++){
   if (color === "black" || color === "#000000") {
    jerseys[j].style.fill = "#222222";
    chgMesh("black");
  } else {
    jerseys[j].style.fill = color;
    var meshColor = pSBC(-0.4, color);
    chgMesh(meshColor);
  } 
  }
     if (color === "black" || color === "#000000") {
    chgMesh("black");
  } else {
    var meshColor = pSBC(-0.4, color);
    chgMesh(meshColor);
  } 
}

function updateName(name) {
  var tempName = document.getElementsByClassName("chgName");
   if (typeof name === "string") {
  for(var n =0; n<tempName.length; n++){
    tempName[n].innerHTML = name;
  }
  } else {
    resetName();
  } 
}

function resetName() {
  var tempName = document.getElementsByClassName("chgName");
  for(var n =0; n<tempName.length; n++){
    tempName[n].innerHTML = "Your Name";
  }
}

function resetNum() {
  var tempNum = document.getElementsByClassName("chgNum");
  for(var n =0; n<tempNum.length; n++){
    tempNum[n].innerHTML = "00";
  }
}

function updateNum(number) {
  var tempNum = document.getElementsByClassName("chgNum");
   if (number) {
  for(var n =0; n<tempNum.length; n++){
    tempNum[n].innerHTML = number;
  }
  } else {
    resetNum();
  } 
}

function getCounter() {
  var temp = document.getElementById("counter").textContent * 1 + 1;
  document.getElementById("counter").innerHTML = temp;
  return temp;
}

function triggerDownload(imgURI, fileName) {
  var evt = new MouseEvent("click", {
    view: window,
    bubbles: false,
    cancelable: true
  });
  var a = document.createElement("a");
  a.setAttribute("download", `${fileName}.png`);
  a.setAttribute("href", imgURI);
  a.setAttribute("target", "_blank");

  a.dispatchEvent(evt);
}

function pushLink(link){
  linkURLs.push(link);
  if(linkURLs.length==2){
    var eName=document.getElementById("name").value;
    var eUsername = document.getElementById("username").value;
    sendToAirtable(eName, eUsername, linkURLs[0], linkURLs[1]);
    console.log(linkURLs.length);
  } else {
    console.log(linkURLs.length);
  }
}

function saveToFirebase(uri, tag) {
  var cnt = getCounter();
  if (
    document.getElementById("name").value == "null" ||
    document.getElementById("name").value == ""
  ) {
    var un = `MakeAGraphic_${tag}_${cnt}`;
  } else {
    var enteredName = document
      .getElementById("name")
      .value.replace(/[^a-zA-Z ]/g, "");
    var un = `${enteredName}_MakeAGraphic_${tag}${cnt}`;
  }
  var firebaseConfig = {
    apiKey: "AIzaSyA4KdxG_idkl5UUWSCoBPVKlLB4NXL_dfI",
    authDomain: "makeagraphic.firebaseapp.com",
    projectId: "makeagraphic",
    storageBucket: "makeagraphic.appspot.com",
    messagingSenderId: "828083981860",
    appId: "1:828083981860:web:bedcdfcbdb5e65d32492b1"
  };
  // Initialize Firebase
  if (!firebase.apps.length) {
    firebase.initializeApp(firebaseConfig);
  } else {
    firebase.app(); // if already initialized, use that one
  }

  if (tag === "base") {
    triggerDownload(uri, un);
  }

  const ref = firebase.storage().ref().child(`${un}.png`);
  const uploadTask = ref.putString(uri, "data_url");

  uploadTask.on(
    "state_changed",
    (snapshot) => {
      // Observe state change events such as progress, pause, and resume
      // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
      var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
      console.log("Upload is " + progress + "% done");
      switch (snapshot.state) {
        case firebase.storage.TaskState.PAUSED: // or 'paused'
          // console.log("Upload is paused");
          break;
        case firebase.storage.TaskState.RUNNING: // or 'running'
          // console.log("Upload is running");
          break;
      }
    },
    (error) => {
      // Handle unsuccessful uploads
      console.error(error);
    },
    () => {
      // Handle successful uploads on complete
      // For instance, get the download URL: https://firebasestorage.googleapis.com/...
      uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => {
        console.log("File available at", downloadURL);
        pushLink(downloadURL);
      });
    }
  );
}

function buildImageUri(svgId, tag, canvasId) {
  var svg = document.getElementById(svgId);
  var canvas = document.getElementById(canvasId);
  var ctx = canvas.getContext("2d");
  var data = new XMLSerializer().serializeToString(svg);
  var DOMURL = window.URL || window.webkitURL || window;

  var img = new Image();
  var svgBlob = new Blob([data], { type: "image/svg+xml;charset=utf-8" });
  var url = DOMURL.createObjectURL(svgBlob);

  img.onload = function () {
    ctx.drawImage(img, 0, 0);
    DOMURL.revokeObjectURL(url);
    var imgURI = canvas.toDataURL("image/png");
    if (tag === "insta") {
      dlink = saveToFirebase(imgURI, "insta");
    } else {
      dlink = saveToFirebase(imgURI, "base");
    }
  };

  img.src = url;
}

var btn = document.getElementById("myBtn");

btn.addEventListener("click", function () {
  buildImageUri("bg2", "base","canvas");
  buildImageUri("bg3", "insta","instaCanvas");
});