const mod = angular.module('pa.animations.class', []),
    directiveName = 'paClass';

mod.directive(directiveName, ($animate) => {
    return {
        restrict: 'A',
        require: [],
        link(scope, element, attrs, controllers) {
            const selfController = controllers[0],
                routerController = controllers[1],
                animationName = attrs.paAnimationName || directiveName,
                className = attrs[directiveName] || directiveName,
                classNameStart = className + '--start',
                status = attrs.paStatus,
                undo = attrs.paUndo,

                setStatus = newStatus => {
                    if (status) {
                        scope[status] = newStatus;
                    }
                },
                setUp = () => {
                    setStatus('READY');
                    element.addClass(classNameStart);
                };

            if (routerController) {
                routerController.register(animationName, selfController);
            }

            setUp();

            scope.$watch(attrs.paActive, (newVal) => {
                if (newVal) {
                    setStatus('RUNNING');

                    $animate.removeClass(
                        element,
                        classNameStart
                    ).then(() => {
                        setStatus('FINISHED');
                        // Used to be necessary in angular 1.3. Tests fail
                        // when called, need to check on demo version.
                        // scope.$apply();
                    });
                } else if (undo) {
                    setUp();
                }

            });

        }
    };
});

export default mod;

@@ -183,251 +183,106 @@
 e: %5B
-%5D,%0A        link(scope, element, attrs, controllers) %7B%0A            const selfController = controllers%5B0%5D,%0A                routerController = controllers%5B1%5D,%0A                animationName = attrs.paAnimationName %7C%7C directiveName,%0A               
+directiveName, '%5E?paRouter'%5D,%0A        controller($q, $scope, $attrs, $element) %7B%0A            const
  cla
@@ -290,16 +290,17 @@
 sName = 
+$
 attrs%5Bdi
@@ -408,19 +408,28 @@
   status
+ScopeVar
  = 
+$
 attrs.pa
@@ -438,45 +438,189 @@
 atus
-,%0A                undo = attrs.paUndo
+;%0A%0A            let status = '',%0A                deferred,%0A%0A%0A                resolve = (...args) =%3E %7B%0A                    return deferred && deferred.resolve(args);%0A                %7D
 ,%0A%0A 
@@ -691,16 +691,24 @@
  (status
+ScopeVar
 ) %7B%0A    
@@ -723,24 +723,25 @@
             
+$
 scope%5Bstatus
@@ -740,16 +740,24 @@
 e%5Bstatus
+ScopeVar
 %5D = newS
@@ -781,24 +781,64 @@
           %7D%0A
+                    status = newStatus;%0A
             
@@ -844,16 +844,17 @@
      %7D,%0A
+%0A
         
@@ -933,24 +933,25 @@
             
+$
 element.addC
@@ -989,17 +989,17 @@
        %7D
-;
+,
 %0A%0A      
@@ -1008,106 +1008,345 @@
     
-if (routerController) %7B%0A                routerController.register(animationName, selfController);%0A
+    clear = () =%3E %7B%0A                    let clearDeferred = $q.defer();%0A                    clearDeferred.resolve();%0A%0A                    if (status === 'RUNNING') %7B%0A                        //TODO we might want to reject this to handle this%0A                        //usecase, needs more cowbell%0A                        resolve();%0A       
     
@@ -1345,35 +1345,44 @@
                 
+ 
 %7D%0A%0A
+        
             setU
@@ -1403,78 +1403,102 @@
     
-scope.$watch(attrs.paActive, (newVal) =%3E %7B%0A                if (newVal)
+        return clearDeferred.promise;%0A                %7D,%0A%0A                runAnimation = () =%3E
  %7B%0A 
@@ -1605,16 +1605,17 @@
         
+$
 element,
@@ -1764,139 +1764,994 @@
     
-// Used to be necessar
+resolve();%0A                    %7D);%0A%0A                %7D,%0A                play = () =%3E %7B%0A                    if (status === 'READY') %7B%0A                        deferred = $q.defer();%0A                        runAnimation();%0A                    %7D%0A                    return deferred.promise;%0A                %7D;%0A%0A            //APIs used b
 y 
+l
 in
- angular 1.3. Tests fail%0A                        // when called, need to check on demo version.%0A         
+king function%0A            this.setUp = setUp;%0A            this.runAnimation = runAnimation;%0A%0A            //Public APIs%0A            this.play = play;%0A            this.resolve = resolve;%0A            this.clear = clear;%0A%0A        %7D,%0A        link(scope, element, attrs, controllers) %7B%0A            const selfController = controllers%5B0%5D,%0A                routerController = controllers%5B1%5D,%0A                animationName = attrs.paAnimationName %7C%7C directiveName;%0A%0A            if (routerController) %7B%0A                routerController.register(animationName, selfController);%0A            %7D%0A%0A            selfController.setUp();%0A            if (attrs.paActive) %7B%0A
     
@@ -2765,18 +2765,16 @@
     
-//
  scope.$
 appl
@@ -2773,41 +2773,137 @@
 pe.$
-apply();%0A                    %7D);%0A
+watch(attrs.paActive, (newVal) =%3E %7B%0A                    if (newVal) %7B%0A                        selfController.runAnimation();%0A    
     
@@ -2925,17 +2925,25 @@
 lse if (
-u
+attrs.paU
 ndo) %7B%0A 
@@ -2953,32 +2953,51 @@
                 
+    selfController.
 setUp();%0A       
@@ -2997,35 +2997,42 @@
                 
-%7D%0A%0A
+    %7D%0A    
             %7D);%0A
@@ -3022,32 +3022,46 @@
              %7D);
+%0A            %7D
 %0A%0A        %7D%0A    

Add paClass Controller APIs #7