
'use strict';

angular.module('app')
  .filter('insightOwnership', function ($window) {

    return function (input, search) {
      var insights = [];
      var only = search === 'mine';
      if(search === 'search'){
        return input;
      }
      var author = JSON.parse($window.sessionStorage.user).username;
    	angular.forEach(input, function(insight, key) {
    	  if(insight.author === author && only){
          insights.push(insight);
        }else if(insight.author !== author && !only){
          insights.push(insight);
        }
    	});
      return insights;
    };
  });
