var angular = require('angular');
var _ = require('jsUtil');
require('../modules');
require('../services/OptionService');

var module = angular.module('flowmodulebase.directives');

module.directive('sinoMabiaoSelect', function(OptionService, $timeout) {
  return {
    restrict: 'E',
    replace: true,
    template: '<select ng-options="::item.value as ::item.text for item in ::options"><option value="">{{defaultTitle}}</option></select>',
    scope: true,
    link: function(scope, element, attrs, ngModelCtrl) {
      var mabiao = attrs.mabiao,
        defaultTitle = attrs.defaultTitle;

      scope.defaultTitle = _.isEmpty(defaultTitle) ? '请选择' :  defaultTitle;
      if(mabiao) {
        OptionService.get(mabiao).then(function(_options) {
          scope.options = _options[0];
        });
      }

    }
  };
});
