'use strict';

var app = app || {};

(function (module){

  const genView= {};


  genView.init = function (){
  $('.survey').hide();
  $('.generator').show();
  genView.populateSlots();
  };

  //  This function will repopulate slots when user clicks re-roll button
  $("#re-roll").click(function(){
    app.genView.populateSlots()
  });


  // append our app.words.slotArray to the DOM
  genView.appendWords = function () {
    app.words.slotArray.forEach( function ( arrayEle, currentIndex, array) {
      let idName = '#slot' + (currentIndex+1);
      let concatType = 'camelCase';

      //If data-saved isn't true, append to DOM
      if ( $(idName).attr('data-saved') !== 'true' ) { 
        switch (concatType) {
          case 'camelCase':
            if (currentIndex > 0) {
              let newElement = arrayEle.split('');
              newElement[0] = newElement[0].toUpperCase();
              $(idName).text(newElement.join(''));
              break;
            } else {
              $(idName).text(arrayEle);
              break;
            }
          case 'hyphenated':
            if (currentIndex > 0) {
              $(idName).text('-' + arrayEle);
              break;
            } else {
              $(idName).text(arrayEle);
              break;
            }
          case 'snakeCase':
            if (currentIndex > 0) {
              $(idName).text('_' + arrayEle);
              break;
            } else {
              $(idName).text(arrayEle);
              break;
            }
          case 'none':
              $(idName).text(arrayEle);
        }
      }

      // Update currentHandle with current displayed handle
      app.words.currentHandle = '';
      for (let i = 0; i < $('.slots').children().length; i++){
          app.words.currentHandle += $('.slots').children().eq(i).text();
      }

      //Add event listener to toggle "data-saved" status
      $(idName).off('click');
      $(idName).on('click',function(){
        $(idName).attr('data-saved') === 'true' ? $(idName).attr('data-saved', false) : $(idName).attr('data-saved', true); 
        console.log(idName,'is clicked. data-saved value is',$(idName).attr('data-saved'))
        })

    });
  }

  // populates our slots.
  genView.populateSlots = function() {
    app.words.randomizeAll()
    genView.appendWords()
  }
  
module.genView = genView

})(app);
@@ -567,24 +567,19 @@
 Type = '
-camelCas
+non
 e';%0A%0A   
@@ -679,16 +679,33 @@
 e' ) %7B %0A
+        debugger%0A
         
@@ -990,89 +990,8 @@
   %7D 
-else %7B%0A              $(idName).text(arrayEle);%0A              break;%0A            %7D
 %0A   
@@ -1137,89 +1137,8 @@
   %7D 
-else %7B%0A              $(idName).text(arrayEle);%0A              break;%0A            %7D
 %0A   
@@ -1283,89 +1283,8 @@
   %7D 
-else %7B%0A              $(idName).text(arrayEle);%0A              break;%0A            %7D
 %0A   
@@ -1335,32 +1335,32 @@
 text(arrayEle);%0A
-
         %7D%0A      
@@ -1353,16 +1353,25 @@
       %7D%0A
+        %0A
       %7D%0A

dry switch code. eliminate unnecessary else statements