'use strict';

(function(module) {

  function MyProject (proj) {
    for (let keys in proj) {
      this[keys] = proj[keys]
    }
    //this.name = proj.name;
    //this.filepath = proj.filepath;
    //this.description = proj.description;
    //this.languages = proj.languages;
  }

  MyProject.allProjects = [];

  MyProject.prototype.toHtml = function() {
    var htmlTemplate = $('#template').html();
    var template = Handlebars.compile(htmlTemplate);
    return template(this);
  };

  MyProject.loadAll = function(project) {
    project.map(function(ele) {
      MyProject.allProjects.push(new MyProject(ele))
    });
  //}
    //project.forEach(function(currentProj) {
    //  MyProject.allProjects.push(new MyProject(currentProj));
  //    var namesOnly = MyProject.allProjects.map(function (currentnewProj) {
  //      return currentnewProj.name;
  //    })
  //    console.log(namesOnly)
    //});
  }

  MyProject.getAll = function() {
    if (localStorage.projects) {
      var lStorageMyProjects = JSON.parse(localStorage.getItem('projects'));
      MyProject.loadAll(lStorageMyProjects)
    } else {
      $.getJSON('./data/projects.json').then(
        function(data) {
          localStorage.setItem('projects', JSON.stringify(data))
          MyProject.loadAll(data);
        }
      );
    }
  };

  MyProject.getAll();
  module.MyProject = MyProject;
  //MyProject.loadAll();
  //MyProject.allProjects.forEach(function(project) {
    //$('#Projects').append(project.toHtml());
})(window);

@@ -128,160 +128,12 @@
   %7D%0A
-    //this.name = proj.name;%0A    //this.filepath = proj.filepath;%0A    //this.description = proj.description;%0A    //this.languages = proj.languages;%0A
   %7D%0A
+
 %0A  M
@@ -470,16 +470,39 @@
 %0A    %7D);
+%0A%0A  //replaced for each
 %0A  //%7D%0A 
@@ -768,16 +768,16 @@
 esOnly)%0A
-
     //%7D)
@@ -778,16 +778,39 @@
   //%7D);%0A
+    TODO: add a reduce%0A
   %7D%0A%0A  M

need to add .reduce