'use strict'; 

app.directive('confirmDelete', function($window) {

  function link(scope, element, attrs) {
    element.on('click', function(event) {
      event.preventDefault();  
      if ($window.confirm('Are you sure you want to delete ' + scope.item.name + '?')) {
        var idx = scope.list.indexOf(scope.item);
        scope.$apply(function() {     
          scope.list.splice(idx, 1);
        });
      }
    });  
  }

  return {
    restrict: 'A',
    scope: {
      item: '=',
      list: '='
    },
    link: link
  };
});