text: angular.module('encore.ui.utilities')
  /**
   * @ngdoc service
   * @name utilities.service:rxFeedbackSvc
   * @description
   * `rxFeedbackSvc` service supports `rxFeedback` directive functionality.  A `custom endpoint` may be set to override
   * the `default` endpoint.
   */
  .factory('rxFeedbackSvc', function ($resource, rxFeedbackApi, $location, $window) {
      var container = {
          api: undefined,
          email: 'encoreui@lists.rackspace.com'
      };
  
      container.setEndpoint = function (url) {
          container.api = $resource(url);
      };
  
      // set a default endpoint
      container.setEndpoint(rxFeedbackApi);
  
      container.fallback = function (feedback) {
          var subject = 'Encore Feedback: ' + feedback.type.label;
          var body = [
              'Current Page: ' + $location.absUrl(),
              'Browser User Agent: ' + navigator.userAgent,
              'Comments: ' + feedback.description
          ];
  
          body = body.join('\n\n');
  
          // if the feedback service fails, this fallback function can be run as a last ditch effort
          var uri = encodeURI('mailto:' + container.email + '?subject=' + subject + '&body=' + body);
          var windowOpen = $window.open(uri, '_blank');
  
          if (!windowOpen) {
              $window.location.href = uri;
          }
      };
  
      return container;
  });
  