text: 'use strict';
  
  /**
   * @ngdoc service
   * @name tagsInputConfig
   * @module ngTagsInput
   *
   * @description
   * Sets global configuration settings for both tagsInput and autoComplete directives. It's also used internally to parse and
   * initialize options from HTML attributes.
   */
  tagsInput.provider('tagsInputConfig', function() {
      var globalDefaults = {}, interpolationStatus = {};
  
      /**
       * @ngdoc method
       * @name setDefaults
       * @description Sets the default configuration option for a directive.
       * @methodOf tagsInputConfig
       *
       * @param {string} directive Name of the directive to be configured. Must be either 'tagsInput' or 'autoComplete'.
       * @param {object} defaults Object containing options and their values.
       *
       * @returns {object} The service itself for chaining purposes.
       */
      this.setDefaults = function(directive, defaults) {
          globalDefaults[directive] = defaults;
          return this;
      };
  
      /***
       * @ngdoc method
       * @name setActiveInterpolation
       * @description Sets active interpolation for a set of options.
       * @methodOf tagsInputConfig
       *
       * @param {string} directive Name of the directive to be configured. Must be either 'tagsInput' or 'autoComplete'.
       * @param {object} options Object containing which options should have interpolation turned on at all times.
       *
       * @returns {object} The service itself for chaining purposes.
       */
      this.setActiveInterpolation = function(directive, options) {
          interpolationStatus[directive] = options;
          return this;
      };
  
      this.$get = function($interpolate) {
          var converters = {};
          converters[String] = function(value) { return value; };
          converters[Number] = function(value) { return parseInt(value, 10); };
          converters[Boolean] = function(value) { return value.toLowerCase() === 'true'; };
          converters[RegExp] = function(value) { return new RegExp(value); };
  
          return {
              load: function(directive, scope, attrs, options) {
                  scope.options = {};
  
                  angular.forEach(options, function(value, key) {
                      var type, localDefault, converter, getDefault, updateValue;
  
                      type = value[0];
                      localDefault = value[1];
                      converter = converters[type];
  
                      getDefault = function() {
                          var globalValue = globalDefaults[directive] && globalDefaults[directive][key];
                          return angular.isDefined(globalValue) ? globalValue : localDefault;
                      };
  
                      updateValue = function(value) {
                          scope.options[key] = value ? converter(value) : getDefault();
                      };
  
                      if (interpolationStatus[directive] && interpolationStatus[directive][key]) {
                          attrs.$observe(key, function(value) {
                              updateValue(value);
                              scope.events.trigger('option-change', { name: key, newValue: value });
                          });
                      }
                      else {
                          updateValue(attrs[key] && $interpolate(attrs[key])(scope.$parent));
                      }
                  });
              }
          };
      };
  });
  