'use strict';
//dependent upon on Bootstrap

app.directive('goBack', function () {
  return {
    restrict: 'E',
    replace: true,
    scope: {
      state: '@',
      stateParams: '@'
    },
    template: '<button class="btn btn-primary" ng-click="goBack()"><i class="fa fa-caret-left"></i> Back</button>',
    controller: function($rootScope, $scope, $state) {
      $scope.goBack = function () {
        //if no state is provided the directive will check the rootScope for the previous state
        if (!$scope.state) {
          $state.go($rootScope.previousState.name, $rootScope.previousState.params);
        } else {
          $state.go($scope.state, $scope.stateParams);
        }
      };

    }
  };
});
