'use strict';

define([

], function () {

  var FileUpload = function (BORAYU, $filter, $http , SweetAlert, $modal) {
    return {
      restrict: 'E',
      scope: {  src:"=" , types:"=" , uri:"=" ,callback:"=" , sizew:"=" , sizeh:"=" , ratio:"="  },
      templateUrl: "modules/components/templates/file-upload.html",
      link: function (scope) {
        // scope, element, attrs
        scope.modalInstance = {};

        scope.open = function(){
          scope.modalInstance = $modal.open({
            animation: true,
            controller:"FileUploadController",
            templateUrl: 'modules/components/templates/file-upload-modal.html',
            size: 'lg',
            resolve: {
              src: function(){ return scope.src;},
              types: function(){ return scope.types;},
              uri: function(){ return scope.uri;},
              sizeW: function(){ return scope.sizew;},
              sizeH: function(){ return scope.sizeh;},
              ratio: function(){ return scope.ratio;}
            }
          });
          scope.modalInstance.result.then(function (imagem) {
             scope.src = imagem;
             if(typeof scope.callback === 'function'){
               scope.callback(imagem);
             }
          });
        };
      }
    };
  };




  return ['BORAYU', '$filter', '$http', 'SweetAlert', '$modal',
  FileUpload];

});
