var angular = require('angular');
require('../modules');

angular
  .module('flowmodulebase.directives')
  .directive('sinoStopOperateInfo', sinoStopOperateInfo)
  .controller('SinoStopOperateInfoController', SinoStopOperateInfoController);

/** @ngInject */
function sinoStopOperateInfo() {
  return {
    restrict: 'E',
    require: 'sinoStopOperateInfo',
    template: '<div class="item item-divider" ng-if="!!infoController.info" style="padding-top: 8px;">' +
      '<span style = "padding:16px;color:red;font-size:16px;white-space:normal;">{{infoController.info}}</span></div>' + 
      '<ng-transclude></ng-transclude>',
    controller: 'SinoStopOperateInfoController',
    controllerAs: 'infoController',
    transclude: true,
    link: function(scope, element, attrs, ctrl) {
      var info = ctrl.getOperateInfo();
      if (info) {
        scope.infoController.info  = '你好！如果要完成' + info + '等功能请在电脑上完成此操作！';
      }
    }
  };
}

function SinoStopOperateInfoController() {
  var self = this,
    getOperateFns = [];
  
  self.registerGetOperateFn = registerGetOperateFn;
  self.getOperateInfo = getOperateInfo;
  
  function registerGetOperateFn(getOperateFn) {
    getOperateFns.push(getOperateFn);
  }
  
  function getOperateInfo() {
    var operateInfos = [];
    
    getOperateFns.forEach(function(getOperateFn) {
      var operate = getOperateFn();
      if (operate.show) {
        operateInfos.push(operate.content);
      }
    });
    return operateInfos.join(',');
  }
}
