/**
 * Created by nalee on 7/21/2016.
 */
angular.module('app.services')
  .factory('imgSync', ['$log','$q','$cordovaFileTransfer', '$http','$ionicLoading','$ionicPopup', function ($log, $q,$http, $cordovaFileTransfer, $ionicLoading,$ionicPopup) {

    return {

      generateSilhouetteList : function(silhouette) {
        var list = [];
        //var log = [];
        angular.forEach(silhouette, function(value, key) {
          list.push(value+'_Back');
          list.push(value+'_Front');
        });
        return list

      },

      loadingPopUp:function(finishedSilhouetteList,silhouetteList,errorFlag){
        var downloadProgress= finishedSilhouetteList.length+"/"+silhouetteList.length;
        $ionicLoading.show({
          template: '<div class="nf-center nf-valign-wrapper"><span>'+downloadProgress+' Please wait...</span></div>'
        });
        if(finishedSilhouetteList.length >= silhouetteList.length){
          $ionicLoading.hide();
          if(errorFlag==true){
            /*var alertPopup = $ionicPopup.alert({
              title: 'Syncing Error',
              template: '<div class="nf-center nf-valign-wrapper">' +
              '<ion-spinner icon="ripple" class="nf-text-white"></ion-spinner>' +
              '<span>Please Resync Silhouette Images</span></div>'
            });*/
            $ionicLoading.hide();

          }
        }
      },
      hidePopUp:function(){
        $ionicLoading.hide();
      },
      listDir: function(path){
        var deferred = $q.defer();

        window.resolveLocalFileSystemURL(path,
        function (fileSystem) {
          var reader = fileSystem.createReader();
          reader.readEntries(
            function (entries) {
              //console.log(entries);
              return deferred.resolve(response);

            },

            function (err) {
              //console.log(err);
              return deferred.reject(err);

            }
          );
        }, function (err) {
          //console.log(err);
            return deferred.reject(err);

          }
      )



    },

      filesToDelete: function(deviceSilhouetteList, silhouetteList){
        var formattedDeviceSilhouetteList=[]

      }


    };
  }])
