'use strict';
/* jshint maxlen: false */

/**
 * @ngdoc overview
 * @name ngAnimate
 * @description
 *
 * # ngAnimate
 *
 * The `ngAnimate` module provides support for JavaScript, CSS3 transition and CSS3 keyframe animation hooks within existing core and custom directives.
 *
 * {@installModule animate}
 *
 *

 *
 * # Usage
 *
 * To see animations in action, all that is required is to define the appropriate CSS classes
 * or to register a JavaScript animation via the myModule.animation() function. The directives that support animation automatically are:
 * `ngRepeat`, `ngInclude`, `ngIf`, `ngSwitch`, `ngShow`, `ngHide`, `ngView` and `ngClass`. Custom directives can take advantage of animation
 * by using the `$animate` service.
 *
 * Below is a more detailed breakdown of the supported animation events provided by pre-existing ng directives:
 *
 * | Directive                                                 | Supported Animations                               |
 * |---------------------------------------------------------- |----------------------------------------------------|
 * | {@link ng.directive:ngRepeat#usage_animations ngRepeat}         | enter, leave and move                              |
 * | {@link ngRoute.directive:ngView#usage_animations ngView}        | enter and leave                                    |
 * | {@link ng.directive:ngInclude#usage_animations ngInclude}       | enter and leave                                    |
 * | {@link ng.directive:ngSwitch#usage_animations ngSwitch}         | enter and leave                                    |
 * | {@link ng.directive:ngIf#usage_animations ngIf}                 | enter and leave                                    |
 * | {@link ng.directive:ngClass#usage_animations ngClass}           | add and remove                                     |
 * | {@link ng.directive:ngShow#usage_animations ngShow & ngHide}    | add and remove (the ng-hide class value)           |
 *
 * You can find out more information about animations upon visiting each directive page.
 *
 * Below is an example of how to apply animations to a directive that supports animation hooks:
 *
 *

 *
 *
 *
 * <ANY class="slide" ng-include="..."></ANY>
 *

 *
 * Keep in mind that if an animation is running, any child elements cannot be animated until the parent element's
 * animation has completed.
 *
 *
CSS-defined Animations

 * The animate service will automatically apply two CSS classes to the animated element and these two CSS classes
 * are designed to contain the start and end CSS styling. Both CSS transitions and keyframe animations are supported
 * and can be used to play along with this naming structure.
 *
 * The following code below demonstrates how to perform animations using **CSS transitions** with Angular:
 *
 *

 *
 *
 *

 *

 *

 *

 *
 * The following code below demonstrates how to perform animations using **CSS animations** with Angular:
 *
 *

 *
 *
 *

 *

 *

 *

 *
 * Both CSS3 animations and transitions can be used together and the animate service will figure out the correct duration and delay timing.
 *
 * Upon DOM mutation, the event class is added first (something like `ng-enter`), then the browser prepares itself to add
 * the active class (in this case `ng-enter-active`) which then triggers the animation. The animation module will automatically
 * detect the CSS code to determine when the animation ends. Once the animation is over then both CSS classes will be
 * removed from the DOM. If a browser does not support CSS transitions or CSS animations then the animation will start and end
 * immediately resulting in a DOM element that is at its final state. This final state is when the DOM element
 * has no CSS transition/animation classes applied to it.
 *
 *
CSS Staggering Animations

 * A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a
 * curtain-like effect. The ngAnimate module, as of 1.2.0, supports staggering animations and the stagger effect can be
 * performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for
 * the animation. The style property expected within the stagger class can either be a **transition-delay** or an
 * **animation-delay** property (or both if your animation contains both transitions and keyframe animations).
 *
 *

 * .my-animation.ng-enter {
 *   /* standard transition code */
 *   -webkit-transition: 1s linear all;
 *   transition: 1s linear all;
 *   opacity:0;
 * }
 * .my-animation.ng-enter-stagger {
 *   /* this will have a 100ms delay between each successive leave animation */
 *   -webkit-transition-delay: 0.1s;
 *   transition-delay: 0.1s;
 *
 *   /* in case the stagger doesn't work then these two values
 *    must be set to 0 to avoid an accidental CSS inheritance */
 *   -webkit-transition-duration: 0s;
 *   transition-duration: 0s;
 * }
 * .my-animation.ng-enter.ng-enter-active {
 *   /* standard transition styles */
 *   opacity:1;
 * }
 *

 *
 * Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations
 * on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this
 * are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation
 * will also be reset if more than 10ms has passed after the last animation has been fired.
 *
 * The following code will issue the **ng-leave-stagger** event on the element provided:
 *
 *

 * var kids = parent.children();
 *
 * $animate.leave(kids[0]); //stagger index=0
 * $animate.leave(kids[1]); //stagger index=1
 * $animate.leave(kids[2]); //stagger index=2
 * $animate.leave(kids[3]); //stagger index=3
 * $animate.leave(kids[4]); //stagger index=4
 *
 * $timeout(function() {
 *   //stagger has reset itself
 *   $animate.leave(kids[5]); //stagger index=0
 *   $animate.leave(kids[6]); //stagger index=1
 * }, 100, false);
 *

 *
 * Stagger animations are currently only supported within CSS-defined animations.
 *
 *
JavaScript-defined Animations

 * In the event that you do not want to use CSS3 transitions or CSS3 animations or if you wish to offer animations on browsers that do not
 * yet support CSS transitions/animations, then you can make use of JavaScript animations defined inside of your AngularJS module.
 *
 *

 * //!annotate="YourApp" Your AngularJS Module|Replace this or ngModule with the module that you used to define your application.
 * var ngModule = angular.module('YourApp', []);
 * ngModule.animation('.my-crazy-animation', function() {
 *   return {
 *     enter: function(element, done) {
 *       //run the animation here and call done when the animation is complete
 *       return function(cancelled) {
 *         //this (optional) function will be called when the animation
 *         //completes or when the animation is cancelled (the cancelled
 *         //flag will be set to true if cancelled).
 *       }
 *     }
 *     leave: function(element, done) { },
 *     move: function(element, done) { },
 *
 *     //animation that can be triggered before the class is added
 *     beforeAddClass: function(element, className, done) { },
 *
 *     //animation that can be triggered after the class is added
 *     addClass: function(element, className, done) { },
 *
 *     //animation that can be triggered before the class is removed
 *     beforeRemoveClass: function(element, className, done) { },
 *
 *     //animation that can be triggered after the class is removed
 *     removeClass: function(element, className, done) { }
 *   }
 * });
 *

 *
 * JavaScript-defined animations are created with a CSS-like class selector and a collection of events which are set to run
 * a javascript callback function. When an animation is triggered, $animate will look for a matching animation which fits
 * the element's CSS class attribute value and then run the matching animation event function (if found).
 * In other words, if the CSS classes present on the animated element match any of the JavaScript animations then the callback function will
 * be executed. It should be also noted that only simple, single class selectors are allowed (compound class selectors are not supported).
 *
 * Within a JavaScript animation, an object containing various event callback animation functions is expected to be returned.
 * As explained above, these callbacks are triggered based on the animation event. Therefore if an enter animation is run,
 * and the JavaScript animation is found, then the enter callback will handle that animation (in addition to the CSS keyframe animation
 * or transition code that is defined via a stylesheet).
 *
 */

angular.module('ngAnimate', ['ng'])

  /**
   * @ngdoc object
   * @name ngAnimate.$animateProvider
   * @description
   *
   * The `$animateProvider` allows developers to register JavaScript animation event handlers directly inside of a module.
   * When an animation is triggered, the $animate service will query the $animate service to find any animations that match
   * the provided name value.
   *
   * Requires the {@link ngAnimate `ngAnimate`} module to be installed.
   *
   * Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
   *
   */
  .config(['$provide', '$animateProvider', function($provide, $animateProvider) {
    var noop = angular.noop;
    var forEach = angular.forEach;
    var selectors = $animateProvider.$$selectors;

    var ELEMENT_NODE = 1;
    var NG_ANIMATE_STATE = '$$ngAnimateState';
    var NG_ANIMATE_CLASS_NAME = 'ng-animate';
    var rootAnimateState = {running: true};

    $provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$timeout', '$rootScope', '$document',
                            function($delegate,   $injector,   $sniffer,   $rootElement,   $timeout,   $rootScope,   $document) {

      $rootElement.data(NG_ANIMATE_STATE, rootAnimateState);

      // disable animations during bootstrap, but once we bootstrapped, enable animations
      $rootScope.$$postDigest(function() {
        rootAnimateState.running = false;
      });

      function lookup(name) {
        if (name) {
          var matches = [],
              flagMap = {},
              classes = name.substr(1).split('.');

          //the empty string value is the default animation
          //operation which performs CSS transition and keyframe
          //animations sniffing. This is always included for each
          //element animation procedure if the browser supports
          //transitions and/or keyframe animations
          if ($sniffer.transitions || $sniffer.animations) {
            classes.push('');
          }

          for(var i=0; i < classes.length; i++) {
            var klass = classes[i],
                selectorFactoryName = selectors[klass];
            if(selectorFactoryName && !flagMap[klass]) {
              matches.push($injector.get(selectorFactoryName));
              flagMap[klass] = true;
            }
          }
          return matches;
        }
      }

      /**
       * @ngdoc object
       * @name ngAnimate.$animate
       * @function
       *
       * @description
       * The `$animate` service provides animation detection support while performing DOM operations (enter, leave and move) as well as during addClass and removeClass operations.
       * When any of these operations are run, the $animate service
       * will examine any JavaScript-defined animations (which are defined by using the $animateProvider provider object)
       * as well as any CSS-defined animations against the CSS classes present on the element once the DOM operation is run.
       *
       * The `$animate` service is used behind the scenes with pre-existing directives and animation with these directives
       * will work out of the box without any extra configuration.
       *
       * Requires the {@link ngAnimate `ngAnimate`} module to be installed.
       *
       * Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
       *
       */
      return {
        /**
         * @ngdoc function
         * @name ngAnimate.$animate#enter
         * @methodOf ngAnimate.$animate
         * @function
         *
         * @description
         * Appends the element to the parentElement element that resides in the document and then runs the enter animation. Once
         * the animation is started, the following CSS classes will be present on the element for the duration of the animation:
         *
         * Below is a breakdown of each step that occurs during enter animation:
         *
         * | Animation Step                                                                               | What the element class attribute looks like |
         * |----------------------------------------------------------------------------------------------|---------------------------------------------|
         * | 1. $animate.enter(...) is called                                                             | class="my-animation"                        |
         * | 2. element is inserted into the parentElement element or beside the afterElement element     | class="my-animation"                        |
         * | 3. $animate runs any JavaScript-defined animations on the element                            | class="my-animation ng-animate"             |
         * | 4. the .ng-enter class is added to the element                                               | class="my-animation ng-animate ng-enter"    |
         * | 5. $animate scans the element styles to get the CSS transition/animation duration and delay  | class="my-animation ng-animate ng-enter"    |
         * | 6. $animate waits for 10ms (this performs a reflow)                                          | class="my-animation ng-animate ng-enter"    |
         * | 7. the .ng-enter-active and .ng-animate-active classes are added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-enter ng-enter-active" |
         * | 8. $animate waits for X milliseconds for the animation to complete                           | class="my-animation ng-animate ng-animate-active ng-enter ng-enter-active" |
         * | 9. The animation ends and all generated CSS classes are removed from the element             | class="my-animation"                        |
         * | 10. The doneCallback() callback is fired (if provided)                                       | class="my-animation"                        |
         *
         * @param {jQuery/jqLite element} element the element that will be the focus of the enter animation
         * @param {jQuery/jqLite element} parentElement the parent element of the element that will be the focus of the enter animation
         * @param {jQuery/jqLite element} afterElement the sibling element (which is the previous element) of the element that will be the focus of the enter animation
         * @param {function()=} doneCallback the callback function that will be called once the animation is complete
        */
        enter : function(element, parentElement, afterElement, doneCallback) {
          this.enabled(false, element);
          $delegate.enter(element, parentElement, afterElement);
          $rootScope.$$postDigest(function() {
            performAnimation('enter', 'ng-enter', element, parentElement, afterElement, noop, doneCallback);
          });
        },

        /**
         * @ngdoc function
         * @name ngAnimate.$animate#leave
         * @methodOf ngAnimate.$animate
         * @function
         *
         * @description
         * Runs the leave animation operation and, upon completion, removes the element from the DOM. Once
         * the animation is started, the following CSS classes will be added for the duration of the animation:
         *
         * Below is a breakdown of each step that occurs during enter animation:
         *
         * | Animation Step                                                                               | What the element class attribute looks like |
         * |----------------------------------------------------------------------------------------------|---------------------------------------------|
         * | 1. $animate.leave(...) is called                                                             | class="my-animation"                        |
         * | 2. $animate runs any JavaScript-defined animations on the element                            | class="my-animation ng-animate"             |
         * | 3. the .ng-leave class is added to the element                                               | class="my-animation ng-animate ng-leave"    |
         * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay  | class="my-animation ng-animate ng-leave"    |
         * | 5. $animate waits for 10ms (this performs a reflow)                                          | class="my-animation ng-animate ng-leave"    |
         * | 6. the .ng-leave-active and .ng-animate-active classes is added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-leave ng-leave-active" |
         * | 7. $animate waits for X milliseconds for the animation to complete                           | class="my-animation ng-animate ng-animate-active ng-leave ng-leave-active" |
         * | 8. The animation ends and all generated CSS classes are removed from the element             | class="my-animation"                        |
         * | 9. The element is removed from the DOM                                                       | ...                                         |
         * | 10. The doneCallback() callback is fired (if provided)                                       | ...                                         |
         *
         * @param {jQuery/jqLite element} element the element that will be the focus of the leave animation
         * @param {function()=} doneCallback the callback function that will be called once the animation is complete
        */
        leave : function(element, doneCallback) {
          cancelChildAnimations(element);
          this.enabled(false, element);
          $rootScope.$$postDigest(function() {
            performAnimation('leave', 'ng-leave', element, null, null, function() {
              $delegate.leave(element);
            }, doneCallback);
          });
        },

        /**
         * @ngdoc function
         * @name ngAnimate.$animate#move
         * @methodOf ngAnimate.$animate
         * @function
         *
         * @description
         * Fires the move DOM operation. Just before the animation starts, the animate service will either append it into the parentElement container or
         * add the element directly after the afterElement element if present. Then the move animation will be run. Once
         * the animation is started, the following CSS classes will be added for the duration of the animation:
         *
         * Below is a breakdown of each step that occurs during move animation:
         *
         * | Animation Step                                                                               | What the element class attribute looks like |
         * |----------------------------------------------------------------------------------------------|---------------------------------------------|
         * | 1. $animate.move(...) is called                                                              | class="my-animation"                        |
         * | 2. element is moved into the parentElement element or beside the afterElement element        | class="my-animation"                        |
         * | 3. $animate runs any JavaScript-defined animations on the element                            | class="my-animation ng-animate"             |
         * | 4. the .ng-move class is added to the element                                                | class="my-animation ng-animate ng-move"     |
         * | 5. $animate scans the element styles to get the CSS transition/animation duration and delay  | class="my-animation ng-animate ng-move"     |
         * | 6. $animate waits for 10ms (this performs a reflow)                                          | class="my-animation ng-animate ng-move"     |
         * | 7. the .ng-move-active and .ng-animate-active classes is added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-move ng-move-active" |
         * | 8. $animate waits for X milliseconds for the animation to complete                           | class="my-animation ng-animate ng-animate-active ng-move ng-move-active" |
         * | 9. The animation ends and all generated CSS classes are removed from the element             | class="my-animation"                        |
         * | 10. The doneCallback() callback is fired (if provided)                                       | class="my-animation"                        |
         *
         * @param {jQuery/jqLite element} element the element that will be the focus of the move animation
         * @param {jQuery/jqLite element} parentElement the parentElement element of the element that will be the focus of the move animation
         * @param {jQuery/jqLite element} afterElement the sibling element (which is the previous element) of the element that will be the focus of the move animation
         * @param {function()=} doneCallback the callback function that will be called once the animation is complete
        */
        move : function(element, parentElement, afterElement, doneCallback) {
          cancelChildAnimations(element);
          this.enabled(false, element);
          $delegate.move(element, parentElement, afterElement);
          $rootScope.$$postDigest(function() {
            performAnimation('move', 'ng-move', element, parentElement, afterElement, noop, doneCallback);
          });
        },

        /**
         * @ngdoc function
         * @name ngAnimate.$animate#addClass
         * @methodOf ngAnimate.$animate
         *
         * @description
         * Triggers a custom animation event based off the className variable and then attaches the className value to the element as a CSS class.
         * Unlike the other animation methods, the animate service will suffix the className value with {@type -add} in order to provide
         * the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if no CSS transitions
         * or keyframes are defined on the -add or base CSS class).
         *
         * Below is a breakdown of each step that occurs during addClass animation:
         *
         * | Animation Step                                                                                | What the element class attribute looks like |
         * |------------------------------------------------------------------------------------------------|---------------------------------------------|
         * | 1. $animate.addClass(element, 'super') is called                                               | class="my-animation"                        |
         * | 2. $animate runs any JavaScript-defined animations on the element                              | class="my-animation ng-animate"             |
         * | 3. the .super-add class are added to the element                                               | class="my-animation ng-animate super-add"   |
         * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay    | class="my-animation ng-animate super-add"   |
         * | 5. $animate waits for 10ms (this performs a reflow)                                            | class="my-animation ng-animate super-add"   |
         * | 6. the .super, .super-add-active and .ng-animate-active classes are added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active super super-add super-add-active"          |
         * | 7. $animate waits for X milliseconds for the animation to complete                             | class="my-animation super-add super-add-active"  |
         * | 8. The animation ends and all generated CSS classes are removed from the element               | class="my-animation super"                  |
         * | 9. The super class is kept on the element                                                      | class="my-animation super"                  |
         * | 10. The doneCallback() callback is fired (if provided)                                         | class="my-animation super"                  |
         *
         * @param {jQuery/jqLite element} element the element that will be animated
         * @param {string} className the CSS class that will be added to the element and then animated
         * @param {function()=} doneCallback the callback function that will be called once the animation is complete
        */
        addClass : function(element, className, doneCallback) {
          performAnimation('addClass', className, element, null, null, function() {
            $delegate.addClass(element, className);
          }, doneCallback);
        },

        /**
         * @ngdoc function
         * @name ngAnimate.$animate#removeClass
         * @methodOf ngAnimate.$animate
         *
         * @description
         * Triggers a custom animation event based off the className variable and then removes the CSS class provided by the className value
         * from the element. Unlike the other animation methods, the animate service will suffix the className value with {@type -remove} in
         * order to provide the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if
         * no CSS transitions or keyframes are defined on the -remove or base CSS classes).
         *
         * Below is a breakdown of each step that occurs during removeClass animation:
         *
         * | Animation Step                                                                                | What the element class attribute looks like     |
         * |-----------------------------------------------------------------------------------------------|---------------------------------------------|
         * | 1. $animate.removeClass(element, 'super') is called                                           | class="my-animation super"                  |
         * | 2. $animate runs any JavaScript-defined animations on the element                             | class="my-animation super ng-animate"       |
         * | 3. the .super-remove class are added to the element                                           | class="my-animation super ng-animate super-remove"|
         * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay   | class="my-animation super ng-animate super-remove"   |
         * | 5. $animate waits for 10ms (this performs a reflow)                                           | class="my-animation super ng-animate super-remove"   |
         * | 6. the .super-remove-active and .ng-animate-active classes are added and .super is removed (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active super-remove super-remove-active"          |
         * | 7. $animate waits for X milliseconds for the animation to complete                            | class="my-animation ng-animate ng-animate-active super-remove super-remove-active"   |
         * | 8. The animation ends and all generated CSS classes are removed from the element              | class="my-animation"                        |
         * | 9. The doneCallback() callback is fired (if provided)                                         | class="my-animation"                        |
         *
         *
         * @param {jQuery/jqLite element} element the element that will be animated
         * @param {string} className the CSS class that will be animated and then removed from the element
         * @param {function()=} doneCallback the callback function that will be called once the animation is complete
        */
        removeClass : function(element, className, doneCallback) {
          performAnimation('removeClass', className, element, null, null, function() {
            $delegate.removeClass(element, className);
          }, doneCallback);
        },

        /**
         * @ngdoc function
         * @name ngAnimate.$animate#enabled
         * @methodOf ngAnimate.$animate
         * @function
         *
         * @param {boolean=} value If provided then set the animation on or off.
         * @param {jQuery/jqLite element=} element If provided then the element will be used to represent the enable/disable operation
         * @return {boolean} Current animation state.
         *
         * @description
         * Globally enables/disables animations.
         *
        */
        enabled : function(value, element) {
          switch(arguments.length) {
            case 2:
              if(value) {
                cleanup(element);
              } else {
                var data = element.data(NG_ANIMATE_STATE) || {};
                data.disabled = true;
                element.data(NG_ANIMATE_STATE, data);
              }
            break;

            case 1:
              rootAnimateState.disabled = !value;
            break;

            default:
              value = !rootAnimateState.disabled;
            break;
          }
          return !!value;
         }
      };

      /*
        all animations call this shared animation triggering function internally.
        The animationEvent variable refers to the JavaScript animation event that will be triggered
        and the className value is the name of the animation that will be applied within the
        CSS code. Element, parentElement and afterElement are provided DOM elements for the animation
        and the onComplete callback will be fired once the animation is fully complete.
      */
      function performAnimation(animationEvent, className, element, parentElement, afterElement, domOperation, doneCallback) {
        var currentClassName = element.attr('class') || '';
        var classes = currentClassName + ' ' + className;
        var animationLookup = (' ' + classes).replace(/\s+/g,'.');
        if (!parentElement) {
          parentElement = afterElement ? afterElement.parent() : element.parent();
        }

        var matches = lookup(animationLookup);
        var isClassBased = animationEvent == 'addClass' || animationEvent == 'removeClass';
        var ngAnimateState = element.data(NG_ANIMATE_STATE) || {};

        //skip the animation if animations are disabled, a parent is already being animated,
        //the element is not currently attached to the document body or then completely close
        //the animation if any matching animations are not found at all.
        //NOTE: IE8 + IE9 should close properly (run closeAnimation()) in case a NO animation is not found.
        if (animationsDisabled(element, parentElement) || matches.length === 0) {
          fireDOMOperation();
          closeAnimation();
          return;
        }

        var animations = [];
        //only add animations if the currently running animation is not structural
        //or if there is no animation running at all
        if(!ngAnimateState.running || !(isClassBased && ngAnimateState.structural)) {
          forEach(matches, function(animation) {
            //add the animation to the queue to if it is allowed to be cancelled
            if(!animation.allowCancel || animation.allowCancel(element, animationEvent, className)) {
              var beforeFn, afterFn = animation[animationEvent];

              //Special case for a leave animation since there is no point in performing an
              //animation on a element node that has already been removed from the DOM
              if(animationEvent == 'leave') {
                beforeFn = afterFn;
                afterFn = null; //this must be falsy so that the animation is skipped for leave
              } else {
                beforeFn = animation['before' + animationEvent.charAt(0).toUpperCase() + animationEvent.substr(1)];
              }
              animations.push({
                before : beforeFn,
                after : afterFn
              });
            }
          });
        }

        //this would mean that an animation was not allowed so let the existing
        //animation do it's thing and close this one early
        if(animations.length === 0) {
          fireDOMOperation();
          fireDoneCallbackAsync();
          return;
        }

        //this value will be searched for class-based CSS className lookup. Therefore,
        //we prefix and suffix the current className value with spaces to avoid substring
        //lookups of className tokens
        var futureClassName = ' ' + currentClassName + ' ';
        if(ngAnimateState.running) {
          //if an animation is currently running on the element then lets take the steps
          //to cancel that animation and fire any required callbacks
          $timeout.cancel(ngAnimateState.closeAnimationTimeout);
          cleanup(element);
          cancelAnimations(ngAnimateState.animations);

          //if the class is removed during the reflow then it will revert the styles temporarily
          //back to the base class CSS styling causing a jump-like effect to occur. This check
          //here ensures that the domOperation is only performed after the reflow has commenced
          if(ngAnimateState.beforeComplete) {
            (ngAnimateState.done || noop)(true);
          } else if(isClassBased && !ngAnimateState.structural) {
            //class-based animations will compare element className values after cancelling the
            //previous animation to see if the element properties already contain the final CSS
            //class and if so then the animation will be skipped. Since the domOperation will
            //be performed only after the reflow is complete then our element's className value
            //will be invalid. Therefore the same string manipulation that would occur within the
            //DOM operation will be performed below so that the class comparison is valid...
            futureClassName = ngAnimateState.event == 'removeClass' ?
              futureClassName.replace(ngAnimateState.className, '') :
              futureClassName + ngAnimateState.className + ' ';
          }
        }

        //There is no point in perform a class-based animation if the element already contains
        //(on addClass) or doesn't contain (on removeClass) the className being animated.
        //The reason why this is being called after the previous animations are cancelled
        //is so that the CSS classes present on the element can be properly examined.
        var classNameToken = ' ' + className + ' ';
        if((animationEvent == 'addClass'    && futureClassName.indexOf(classNameToken) >= 0) ||
           (animationEvent == 'removeClass' && futureClassName.indexOf(classNameToken) == -1)) {
          fireDOMOperation();
          fireDoneCallbackAsync();
          return;
        }

        //the ng-animate class does nothing, but it's here to allow for
        //parent animations to find and cancel child animations when needed
        element.addClass(NG_ANIMATE_CLASS_NAME);

        element.data(NG_ANIMATE_STATE, {
          running:true,
          event:animationEvent,
          className:className,
          structural:!isClassBased,
          animations:animations,
          done:onBeforeAnimationsComplete
        });

        //first we run the before animations and when all of those are complete
        //then we perform the DOM operation and run the next set of animations
        invokeRegisteredAnimationFns(animations, 'before', onBeforeAnimationsComplete);

        function onBeforeAnimationsComplete(cancelled) {
          fireDOMOperation();
          if(cancelled === true) {
            closeAnimation();
            return;
          }

          //set the done function to the final done function
          //so that the DOM event won't be executed twice by accident
          //if the after animation is cancelled as well
          var data = element.data(NG_ANIMATE_STATE);
          if(data) {
            data.done = closeAnimation;
            element.data(NG_ANIMATE_STATE, data);
          }
          invokeRegisteredAnimationFns(animations, 'after', closeAnimation);
        }

        function invokeRegisteredAnimationFns(animations, phase, allAnimationFnsComplete) {
          var endFnName = phase + 'End';
          forEach(animations, function(animation, index) {
            var animationPhaseCompleted = function() {
              progress(index, phase);
            };

            //there are no before functions for enter + move since the DOM
            //operations happen before the performAnimation method fires
            if(phase == 'before' && (animationEvent == 'enter' || animationEvent == 'move')) {
              animationPhaseCompleted();
              return;
            }

            if(animation[phase]) {
              animation[endFnName] = isClassBased ?
                animation[phase](element, className, animationPhaseCompleted) :
                animation[phase](element, animationPhaseCompleted);
            } else {
              animationPhaseCompleted();
            }
          });

          function progress(index, phase) {
            var phaseCompletionFlag = phase + 'Complete';
            var currentAnimation = animations[index];
            currentAnimation[phaseCompletionFlag] = true;
            (currentAnimation[endFnName] || noop)();

            for(var i=0;i<animations.length;i++) {
              if(!animations[i][phaseCompletionFlag]) return;
            }

            allAnimationFnsComplete();
          }
        }

        function fireDoneCallbackAsync() {
          doneCallback && $timeout(doneCallback, 0, false);
        }

        //it is less complicated to use a flag than managing and cancelling
        //timeouts containing multiple callbacks.
        function fireDOMOperation() {
          if(!fireDOMOperation.hasBeenRun) {
            fireDOMOperation.hasBeenRun = true;
            domOperation();
          }
        }

        function closeAnimation() {
          if(!closeAnimation.hasBeenRun) {
            closeAnimation.hasBeenRun = true;
            var data = element.data(NG_ANIMATE_STATE);
            if(data) {
              /* only structural animations wait for reflow before removing an
                 animation, but class-based animations don't. An example of this
                 failing would be when a parent HTML tag has a ng-class attribute
                 causing ALL directives below to skip animations during the digest */
              if(isClassBased) {
                cleanup(element);
              } else {
                data.closeAnimationTimeout = $timeout(function() {
                  cleanup(element);
                }, 0, false);
                element.data(NG_ANIMATE_STATE, data);
              }
            }
            fireDoneCallbackAsync();
          }
        }
      }

      function cancelChildAnimations(element) {
        var node = element[0];
        if(node.nodeType != ELEMENT_NODE) {
          return;
        }

        forEach(node.querySelectorAll('.' + NG_ANIMATE_CLASS_NAME), function(element) {
          element = angular.element(element);
          var data = element.data(NG_ANIMATE_STATE);
          if(data) {
            cancelAnimations(data.animations);
            cleanup(element);
          }
        });
      }

      function cancelAnimations(animations) {
        var isCancelledFlag = true;
        forEach(animations, function(animation) {
          if(!animations.beforeComplete) {
            (animation.beforeEnd || noop)(isCancelledFlag);
          }
          if(!animations.afterComplete) {
            (animation.afterEnd || noop)(isCancelledFlag);
          }
        });
      }

      function cleanup(element) {
        if(element[0] == $rootElement[0]) {
          if(!rootAnimateState.disabled) {
            rootAnimateState.running = false;
            rootAnimateState.structural = false;
          }
        } else {
          element.removeClass(NG_ANIMATE_CLASS_NAME);
          element.removeData(NG_ANIMATE_STATE);
        }
      }

      function animationsDisabled(element, parentElement) {
        if (rootAnimateState.disabled) return true;

        if(element[0] == $rootElement[0]) {
          return rootAnimateState.disabled || rootAnimateState.running;
        }

        do {
          //the element did not reach the root element which means that it
          //is not apart of the DOM. Therefore there is no reason to do
          //any animations on it
          if(parentElement.length === 0) break;

          var isRoot = parentElement[0] == $rootElement[0];
          var state = isRoot ? rootAnimateState : parentElement.data(NG_ANIMATE_STATE);
          var result = state && (!!state.disabled || !!state.running);
          if(isRoot || result) {
            return result;
          }

          if(isRoot) return true;
        }
        while(parentElement = parentElement.parent());

        return true;
      }
    }]);

    $animateProvider.register('', ['$window', '$sniffer', '$timeout', function($window, $sniffer, $timeout) {
      // Detect proper transitionend/animationend event names.
      var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT;

      // If unprefixed events are not supported but webkit-prefixed are, use the latter.
      // Otherwise, just use W3C names, browsers not supporting them at all will just ignore them.
      // Note: Chrome implements `window.onwebkitanimationend` and doesn't implement `window.onanimationend`
      // but at the same time dispatches the `animationend` event and not `webkitAnimationEnd`.
      // Register both events in case `window.onanimationend` is not supported because of that,
      // do the same for `transitionend` as Safari is likely to exhibit similar behavior.
      // Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
      // therefore there is no reason to test anymore for other vendor prefixes: http://caniuse.com/#search=transition
      if (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {
        CSS_PREFIX = '-webkit-';
        TRANSITION_PROP = 'WebkitTransition';
        TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
      } else {
        TRANSITION_PROP = 'transition';
        TRANSITIONEND_EVENT = 'transitionend';
      }

      if (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {
        CSS_PREFIX = '-webkit-';
        ANIMATION_PROP = 'WebkitAnimation';
        ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
      } else {
        ANIMATION_PROP = 'animation';
        ANIMATIONEND_EVENT = 'animationend';
      }

      var DURATION_KEY = 'Duration';
      var PROPERTY_KEY = 'Property';
      var DELAY_KEY = 'Delay';
      var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
      var NG_ANIMATE_PARENT_KEY = '$$ngAnimateKey';
      var NG_ANIMATE_CSS_DATA_KEY = '$$ngAnimateCSS3Data';
      var NG_ANIMATE_FALLBACK_CLASS_NAME = 'ng-animate-start';
      var NG_ANIMATE_FALLBACK_ACTIVE_CLASS_NAME = 'ng-animate-active';

      var lookupCache = {};
      var parentCounter = 0;

      var animationReflowQueue = [], animationTimer, timeOut = false;
      function afterReflow(callback) {
        animationReflowQueue.push(callback);
        $timeout.cancel(animationTimer);
        animationTimer = $timeout(function() {
          forEach(animationReflowQueue, function(fn) {
            fn();
          });
          animationReflowQueue = [];
          animationTimer = null;
          lookupCache = {};
        }, 10, false);
      }

      function applyStyle(node, style) {
        var oldStyle = node.getAttribute('style') || '';
        var newStyle = (oldStyle.length > 0 ? '; ' : '') + style;
        node.setAttribute('style', newStyle);
        return oldStyle;
      }

      function getElementAnimationDetails(element, cacheKey) {
        var data = cacheKey ? lookupCache[cacheKey] : null;
        if(!data) {
          var transitionDuration = 0;
          var transitionDelay = 0;
          var animationDuration = 0;
          var animationDelay = 0;
          var transitionDelayStyle;
          var animationDelayStyle;
          var transitionDurationStyle;
          var transitionPropertyStyle;

          //we want all the styles defined before and after
          forEach(element, function(element) {
            if (element.nodeType == ELEMENT_NODE) {
              var elementStyles = $window.getComputedStyle(element) || {};

              transitionDurationStyle = elementStyles[TRANSITION_PROP + DURATION_KEY];

              transitionDuration = Math.max(parseMaxTime(transitionDurationStyle), transitionDuration);

              transitionPropertyStyle = elementStyles[TRANSITION_PROP + PROPERTY_KEY];

              transitionDelayStyle = elementStyles[TRANSITION_PROP + DELAY_KEY];

              transitionDelay  = Math.max(parseMaxTime(transitionDelayStyle), transitionDelay);

              animationDelayStyle = elementStyles[ANIMATION_PROP + DELAY_KEY];

              animationDelay   = Math.max(parseMaxTime(animationDelayStyle), animationDelay);

              var aDuration  = parseMaxTime(elementStyles[ANIMATION_PROP + DURATION_KEY]);

              if(aDuration > 0) {
                aDuration *= parseInt(elementStyles[ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY], 10) || 1;
              }

              animationDuration = Math.max(aDuration, animationDuration);
            }
          });
          data = {
            total : 0,
            transitionPropertyStyle: transitionPropertyStyle,
            transitionDurationStyle: transitionDurationStyle,
            transitionDelayStyle: transitionDelayStyle,
            transitionDelay: transitionDelay,
            transitionDuration: transitionDuration,
            animationDelayStyle: animationDelayStyle,
            animationDelay: animationDelay,
            animationDuration: animationDuration
          };
          if(cacheKey) {
            lookupCache[cacheKey] = data;
          }
        }
        return data;
      }

      function parseMaxTime(str) {
        var maxValue = 0;
        var values = angular.isString(str) ?
          str.split(/\s*,\s*/) :
          [];
        forEach(values, function(value) {
          maxValue = Math.max(parseFloat(value) || 0, maxValue);
        });
        return maxValue;
      }

      function getCacheKey(element) {
        var parentElement = element.parent();
        var parentID = parentElement.data(NG_ANIMATE_PARENT_KEY);
        if(!parentID) {
          parentElement.data(NG_ANIMATE_PARENT_KEY, ++parentCounter);
          parentID = parentCounter;
        }
        return parentID + '-' + element[0].className;
      }

      function animateSetup(element, className) {
        var cacheKey = getCacheKey(element);
        var eventCacheKey = cacheKey + ' ' + className;
        var stagger = {};
        var ii = lookupCache[eventCacheKey] ? ++lookupCache[eventCacheKey].total : 0;

        if(ii > 0) {
          var staggerClassName = className + '-stagger';
          var staggerCacheKey = cacheKey + ' ' + staggerClassName;
          var applyClasses = !lookupCache[staggerCacheKey];

          applyClasses && element.addClass(staggerClassName);

          stagger = getElementAnimationDetails(element, staggerCacheKey);

          applyClasses && element.removeClass(staggerClassName);
        }

        element.addClass(className);

        var timings = getElementAnimationDetails(element, eventCacheKey);

        /* there is no point in performing a reflow if the animation
           timeout is empty (this would cause a flicker bug normally
           in the page. There is also no point in performing an animation
           that only has a delay and no duration */
        var maxDuration = Math.max(timings.transitionDuration, timings.animationDuration);
        if(maxDuration === 0) {
          element.removeClass(className);
          return false;
        }

        var node = element[0];
        //temporarily disable the transition so that the enter styles
        //don't animate twice (this is here to avoid a bug in Chrome/FF).
        var activeClassName = '';
        if(timings.transitionDuration > 0) {
          element.addClass(NG_ANIMATE_FALLBACK_CLASS_NAME);
          activeClassName += NG_ANIMATE_FALLBACK_ACTIVE_CLASS_NAME + ' ';
          blockTransitions(element);
        } else {
          blockKeyframeAnimations(element);
        }

        forEach(className.split(' '), function(klass, i) {
          activeClassName += (i > 0 ? ' ' : '') + klass + '-active';
        });

        element.data(NG_ANIMATE_CSS_DATA_KEY, {
          className : className,
          activeClassName : activeClassName,
          maxDuration : maxDuration,
          classes : className + ' ' + activeClassName,
          timings : timings,
          stagger : stagger,
          ii : ii
        });

        return true;
      }

      function blockTransitions(element) {
        element[0].style[TRANSITION_PROP + PROPERTY_KEY] = 'none';
      }

      function blockKeyframeAnimations(element) {
        element[0].style[ANIMATION_PROP] = 'none 0s';
      }

      function unblockTransitions(element) {
        var node = element[0], prop = TRANSITION_PROP + PROPERTY_KEY;
        if(node.style[prop] && node.style[prop].length > 0) {
          node.style[prop] = '';
        }
      }

      function unblockKeyframeAnimations(element) {
        element[0].style[ANIMATION_PROP] = '';
      }

      function animateRun(element, className, activeAnimationComplete) {
        var data = element.data(NG_ANIMATE_CSS_DATA_KEY);
        if(!element.hasClass(className) || !data) {
          activeAnimationComplete();
          return;
        }

        var node = element[0];
        var timings = data.timings;
        var stagger = data.stagger;
        var maxDuration = data.maxDuration;
        var activeClassName = data.activeClassName;
        var maxDelayTime = Math.max(timings.transitionDelay, timings.animationDelay) * 1000;
        var startTime = Date.now();
        var css3AnimationEvents = ANIMATIONEND_EVENT + ' ' + TRANSITIONEND_EVENT;
        var formerStyle;
        var ii = data.ii;

        var applyFallbackStyle, style = '';
        if(timings.transitionDuration > 0) {
          var propertyStyle = timings.transitionPropertyStyle;
          if(propertyStyle.indexOf('all') == -1) {
            applyFallbackStyle = true;
            var fallbackProperty = $sniffer.msie ? '-ms-zoom' : 'border-spacing';
            style += CSS_PREFIX + 'transition-property: ' + propertyStyle + ', ' + fallbackProperty + '; ';
            style += CSS_PREFIX + 'transition-duration: ' + timings.transitionDurationStyle + ', ' + timings.transitionDuration + 's; ';
          }
        } else {
          unblockKeyframeAnimations(element);
        }

        if(ii > 0) {
          if(stagger.transitionDelay > 0 && stagger.transitionDuration === 0) {
            var delayStyle = timings.transitionDelayStyle;
            if(applyFallbackStyle) {
              delayStyle += ', ' + timings.transitionDelay + 's';
            }

            style += CSS_PREFIX + 'transition-delay: ' +
                     prepareStaggerDelay(delayStyle, stagger.transitionDelay, ii) + '; ';
          }

          if(stagger.animationDelay > 0 && stagger.animationDuration === 0) {
            style += CSS_PREFIX + 'animation-delay: ' +
                     prepareStaggerDelay(timings.animationDelayStyle, stagger.animationDelay, ii) + '; ';
          }
        }

        if(style.length > 0) {
          formerStyle = applyStyle(node, style);
        }

        element.on(css3AnimationEvents, onAnimationProgress);
        element.addClass(activeClassName);

        // This will automatically be called by $animate so
        // there is no need to attach this internally to the
        // timeout done method.
        return function onEnd(cancelled) {
          element.off(css3AnimationEvents, onAnimationProgress);
          element.removeClass(activeClassName);
          animateClose(element, className);
          if(formerStyle != null) {
            formerStyle.length > 0 ?
              node.setAttribute('style', formerStyle) :
              node.removeAttribute('style');
          }
        };

        function onAnimationProgress(event) {
          event.stopPropagation();
          var ev = event.originalEvent || event;
          var timeStamp = ev.$manualTimeStamp || ev.timeStamp || Date.now();
          /* $manualTimeStamp is a mocked timeStamp value which is set
           * within browserTrigger(). This is only here so that tests can
           * mock animations properly. Real events fallback to event.timeStamp,
           * or, if they don't, then a timeStamp is automatically created for them.
           * We're checking to see if the timeStamp surpasses the expected delay,
           * but we're using elapsedTime instead of the timeStamp on the 2nd
           * pre-condition since animations sometimes close off early */
          if(Math.max(timeStamp - startTime, 0) >= maxDelayTime && ev.elapsedTime >= maxDuration) {
            activeAnimationComplete();
          }
        }
      }

      function prepareStaggerDelay(delayStyle, staggerDelay, index) {
        var style = '';
        forEach(delayStyle.split(','), function(val, i) {
          style += (i > 0 ? ',' : '') +
                   (index * staggerDelay + parseInt(val, 10)) + 's';
        });
        return style;
      }

      function animateBefore(element, className) {
        if(animateSetup(element, className)) {
          return function(cancelled) {
            cancelled && animateClose(element, className);
          };
        }
      }

      function animateAfter(element, className, afterAnimationComplete) {
        if(element.data(NG_ANIMATE_CSS_DATA_KEY)) {
          return animateRun(element, className, afterAnimationComplete);
        } else {
          animateClose(element, className);
          afterAnimationComplete();
        }
      }

      function animate(element, className, animationComplete) {
        //If the animateSetup function doesn't bother returning a
        //cancellation function then it means that there is no animation
        //to perform at all
        var preReflowCancellation = animateBefore(element, className);
        if(!preReflowCancellation) {
          animationComplete();
          return;
        }

        //There are two cancellation functions: one is before the first
        //reflow animation and the second is during the active state
        //animation. The first function will take care of removing the
        //data from the element which will not make the 2nd animation
        //happen in the first place
        var cancel = preReflowCancellation;
        afterReflow(function() {
          unblockTransitions(element);
          //once the reflow is complete then we point cancel to
          //the new cancellation function which will remove all of the
          //animation properties from the active animation
          cancel = animateAfter(element, className, animationComplete);
        });

        return function(cancelled) {
          (cancel || noop)(cancelled);
        };
      }

      function animateClose(element, className) {
        element.removeClass(className);
        element.removeClass(NG_ANIMATE_FALLBACK_CLASS_NAME);
        element.removeData(NG_ANIMATE_CSS_DATA_KEY);
      }

      return {
        allowCancel : function(element, animationEvent, className) {
          //always cancel the current animation if it is a
          //structural animation
          var oldClasses = (element.data(NG_ANIMATE_CSS_DATA_KEY) || {}).classes;
          if(!oldClasses || ['enter','leave','move'].indexOf(animationEvent) >= 0) {
            return true;
          }

          var parentElement = element.parent();
          var clone = angular.element(element[0].cloneNode());

          //make the element super hidden and override any CSS style values
          clone.attr('style','position:absolute; top:-9999px; left:-9999px');
          clone.removeAttr('id');
          clone.html('');

          forEach(oldClasses.split(' '), function(klass) {
            clone.removeClass(klass);
          });

          var suffix = animationEvent == 'addClass' ? '-add' : '-remove';
          clone.addClass(suffixClasses(className, suffix));
          parentElement.append(clone);

          var timings = getElementAnimationDetails(clone);
          clone.remove();

          return Math.max(timings.transitionDuration, timings.animationDuration) > 0;
        },

        enter : function(element, animationCompleted) {
          return animate(element, 'ng-enter', animationCompleted);
        },

        leave : function(element, animationCompleted) {
          return animate(element, 'ng-leave', animationCompleted);
        },

        move : function(element, animationCompleted) {
          return animate(element, 'ng-move', animationCompleted);
        },

        beforeAddClass : function(element, className, animationCompleted) {
          var cancellationMethod = animateBefore(element, suffixClasses(className, '-add'));
          if(cancellationMethod) {
            afterReflow(function() {
              unblockTransitions(element);
              animationCompleted();
            });
            return cancellationMethod;
          }
          animationCompleted();
        },

        addClass : function(element, className, animationCompleted) {
          return animateAfter(element, suffixClasses(className, '-add'), animationCompleted);
        },

        beforeRemoveClass : function(element, className, animationCompleted) {
          var cancellationMethod = animateBefore(element, suffixClasses(className, '-remove'));
          if(cancellationMethod) {
            afterReflow(function() {
              unblockTransitions(element);
              animationCompleted();
            });
            return cancellationMethod;
          }
          animationCompleted();
        },

        removeClass : function(element, className, animationCompleted) {
          return animateAfter(element, suffixClasses(className, '-remove'), animationCompleted);
        }
      };

      function suffixClasses(classes, suffix) {
        var className = '';
        classes = angular.isArray(classes) ? classes : classes.split(/\s+/);
        forEach(classes, function(klass, i) {
          if(klass && klass.length > 0) {
            className += (i > 0 ? ' ' : '') + klass + suffix;
          }
        });
        return className;
      }
    }]);
  }]);


namespace base { class Thread; }

namespace sandbox {

class SANDBOX_EXPORT ThreadHelpers {
 public:
  // Check whether the current process is single threaded. |proc_fd|
  // must be a file descriptor to /proc/ and remains owned by the
  // caller.
  static bool IsSingleThreaded(int proc_fd);
  static bool IsSingleThreaded();

  // Crash if the current process is not single threaded. This will wait
  // on /proc to be updated. In the case where this doesn't crash, this will
  // return promptly. In the case where this does crash, this will first wait
  // for a few ms in Debug mode, a few seconds in Release mode.
  static void AssertSingleThreaded(int proc_fd);
  static void AssertSingleThreaded();

  // Stop |thread| and ensure that it does not have an entry in
  // /proc/self/task/ from the point of view of the current thread. This is
  // the way to stop threads before calling IsSingleThreaded().
  static bool StopThreadAndWatchProcFS(int proc_fd, base::Thread* thread);

  static const char* GetAssertSingleThreadedErrorMessageForTests();

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadHelpers);
};

}  // namespace sandbox

#endif  // SANDBOX_LINUX_SERVICES_THREAD_HELPERS_H_


package io.leangen.graphql.generator.mapping;

import io.leangen.graphql.util.ClassUtils;

import java.lang.reflect.AnnotatedType;

public abstract class AbstractSimpleTypeAdapter<T, S> extends AbstractTypeAdapter<T, S> {

    @SuppressWarnings("WeakerAccess")
    protected final Class<?> rawSourceType;

    protected AbstractSimpleTypeAdapter() {
        this.rawSourceType = ClassUtils.getRawType(sourceType.getType());
    }

    @Override
    public boolean supports(AnnotatedType type) {
        return ClassUtils.isSuperClass(rawSourceType, type);
    }
}


<?php
/**
 * Adds methods for limited kinds of faceting using the silverstripe ORM.
 * This is used by the default ShopSearchSimple adapter but also can
 * be added to other contexts (such as ProductCategory).
 *
 * TODO: Facet class + subclasses
 *
 * @author Mark Guinn <mark@adaircreative.com>
 * @date 10.21.2013
 * @package shop_search
 * @subpackage helpers
 */
class FacetHelper extends Object
{
    /** @var bool - if this is turned on it will use an algorithm that doesn't require traversing the data set if possible */
    private static $faster_faceting = false;

    /** @var bool - should the facets (link and checkbox only) be sorted - this can mess with things like category lists */
    private static $sort_facet_values = true;

    /** @var string - I don't know why you'd want to override this, but you could if you wanted */
    private static $attribute_facet_regex = '/^ATT(\d+)$/';

    /** @var bool - For checkbox facets, is the initial state all checked or all unchecked? */
    private static $default_checkbox_state = true;

    /**
     * @return FacetHelper
     */
    public static function inst()
    {
        return Injector::inst()->get('FacetHelper');
    }

    /**
     * Performs some quick pre-processing on filters from any source
     *
     * @param array $filters
     * @return array
     */
    public function scrubFilters($filters)
    {
        if (!is_array($filters)) {
            $filters = array();
        }

        foreach ($filters as $k => $v) {
            if (empty($v)) {
                unset($filters[$k]);
            }
            // this allows you to send an array as a comma-separated list, which is easier on the query string length
            if (is_string($v) && strpos($v, 'LIST~') === 0) {
                $filters[$k] = explode(',', substr($v, 5));
            }
        }

        return $filters;
    }

    /**
     * @param DataList $list
     * @param array    $filters
     * @param DataObject|string $sing - just a singleton object we can get information off of
     * @return DataList
     */
    public function addFiltersToDataList($list, array $filters, $sing=null)
    {
        if (!$sing) {
            $sing = singleton($list->dataClass());
        }
        if (is_string($sing)) {
            $sing = singleton($sing);
        }

        if (!empty($filters)) {
            foreach ($filters as $filterField => $filterVal) {
                if ($sing->hasExtension('HasStaticAttributes') && preg_match(self::config()->attribute_facet_regex, $filterField, $matches)) {
                    //					$sav = $sing->StaticAttributeValues();
//					Debug::log("sav = {$sav->getJoinTable()}, {$sav->getLocalKey()}, {$sav->getForeignKey()}");
//					$list = $list
//						->innerJoin($sav->getJoinTable(), "\"{$sing->baseTable()}\".\"ID\" = \"{$sav->getJoinTable()}\".\"{$sav->getLocalKey()}\"")
//						->filter("\"{$sav->getJoinTable()}\".\"{$sav->getForeignKey()}\"", $filterVal)
//					;
                    // TODO: This logic should be something like the above, but I don't know
                    // how to get the join table from a singleton (which returns an UnsavedRelationList
                    // instead of a ManyManyList). I've got a deadline to meet, though, so this
                    // will catch the majority of cases as long as the extension is applied to the
                    // Product class instead of a subclass.
                    $list = $list
                        ->innerJoin('Product_StaticAttributeTypes', "\"SiteTree\".\"ID\" = \"Product_StaticAttributeTypes\".\"ProductID\"")
                        ->innerJoin('ProductAttributeValue', "\"Product_StaticAttributeTypes\".\"ProductAttributeTypeID\" = \"ProductAttributeValue\".\"TypeID\"")
                        ->innerJoin('Product_StaticAttributeValues', "\"SiteTree\".\"ID\" = \"Product_StaticAttributeValues\".\"ProductID\" AND \"ProductAttributeValue\".\"ID\" = \"Product_StaticAttributeValues\".\"ProductAttributeValueID\"")
                        ->filter("Product_StaticAttributeValues.ProductAttributeValueID", $filterVal);
                } else {
                    $list = $list->filter($this->processFilterField($sing, $filterField, $filterVal));
                }
            }
        }

        return $list;
    }

    /**
     * @param DataObject $rec           This would normally just be a singleton but we don't want to have to create it over and over
     * @param string     $filterField
     * @param mixed      $filterVal
     * @return array - returns the new filter added
     */
    public function processFilterField($rec, $filterField, $filterVal)
    {
        // First check for VFI fields
        if ($rec->hasExtension('VirtualFieldIndex') && ($spec = $rec->getVFISpec($filterField))) {
            if ($spec['Type'] == VirtualFieldIndex::TYPE_LIST) {
                // Lists have to be handled a little differently
                $f = $rec->getVFIFieldName($filterField) . ':PartialMatch';
                if (is_array($filterVal)) {
                    foreach ($filterVal as &$val) {
                        $val = '|' . $val . '|';
                    }
                    return array($f => $filterVal);
                } else {
                    return array($f => '|' . $filterVal . '|');
                }
            } else {
                // Simples are simple
                $filterField = $rec->getVFIFieldName($filterField);
            }
        }

        // Next check for regular db fields
        if ($rec->dbObject($filterField)) {
            // Is it a range value?
            if (is_string($filterVal) && preg_match('/^RANGE\~(.+)\~(.+)$/', $filterVal, $m)) {
                $filterField .= ':Between';
                $filterVal = array_slice($m, 1, 2);
            }

            return array($filterField => $filterVal);
        }

        return array();
    }

    /**
     * Processes the facet spec and removes any shorthand (field => label).
     * @param array $facetSpec
     * @return array
     */
    public function expandFacetSpec(array $facetSpec)
    {
        if (is_null($facetSpec)) {
            return array();
        }
        $facets = array();

        foreach ($facetSpec as $field => $label) {
            if (is_array($label)) {
                $facets[$field] = $label;
            } else {
                $facets[$field] = array('Label' => $label);
            }

            if (empty($facets[$field]['Source'])) {
                $facets[$field]['Source'] = $field;
            }
            if (empty($facets[$field]['Type'])) {
                $facets[$field]['Type']  = ShopSearch::FACET_TYPE_LINK;
            }

            if (empty($facets[$field]['Values'])) {
                $facets[$field]['Values'] = array();
            } else {
                $vals = $facets[$field]['Values'];
                if (is_string($vals)) {
                    $vals = eval('return ' . $vals . ';');
                }
                $facets[$field]['Values'] = array();
                foreach ($vals as $val => $lbl) {
                    $facets[$field]['Values'][$val] = new ArrayData(array(
                        'Label'     => $lbl,
                        'Value'     => $val,
                        'Count'     => 0,
                    ));
                }
            }
        }

        return $facets;
    }

    /**
     * This is super-slow. I'm assuming if you're using facets you
     * probably also ought to be using Solr or something else. Or
     * maybe you have unlimited time and can refactor this feature
     * and submit a pull request...
     *
     * TODO: If this is going to be used for categories we're going
     * to have to really clean it up and speed it up.
     * Suggestion:
     *  - option to turn off counts
     *  - switch order of nested array so we don't go through results unless needed
     *  - if not doing counts, min/max and link facets can be handled w/ queries
     *  - separate that bit out into a new function
     * NOTE: This is partially done with the "faster_faceting" config
     * option but more could be done, particularly by covering link facets as well.
     *
     * Output - list of ArrayData in the format:
     *   Label - name of the facet
     *   Source - field name of the facet
     *   Type - one of the ShopSearch::FACET_TYPE_XXXX constants
     *   Values - SS_List of possible values for this facet
     *
     * @param SS_List $matches
     * @param array $facetSpec
     * @param bool $autoFacetAttributes [optional]
     * @return ArrayList
     */
    public function buildFacets(SS_List $matches, array $facetSpec, $autoFacetAttributes=false)
    {
        $facets = $this->expandFacetSpec($facetSpec);
        if (!$autoFacetAttributes && (empty($facets) || !$matches || !$matches->count())) {
            return new ArrayList();
        }
        $fasterMethod = (bool)$this->config()->faster_faceting;

        // fill them in
        foreach ($facets as $field => &$facet) {
            if (preg_match(self::config()->attribute_facet_regex, $field, $m)) {
                $this->buildAttributeFacet($matches, $facet, $m[1]);
                continue;
            }

            // NOTE: using this method range and checkbox facets don't get counts
            if ($fasterMethod && $facet['Type'] != ShopSearch::FACET_TYPE_LINK) {
                if ($facet['Type'] == ShopSearch::FACET_TYPE_RANGE) {
                    if (isset($facet['RangeMin'])) {
                        $facet['MinValue'] = $facet['RangeMin'];
                    }
                    if (isset($facet['RangeMax'])) {
                        $facet['MaxValue'] = $facet['RangeMax'];
                    }
                }

                continue;
            }

            foreach ($matches as $rec) {
                // If it's a range facet, set up the min/max
                if ($facet['Type'] == ShopSearch::FACET_TYPE_RANGE) {
                    if (isset($facet['RangeMin'])) {
                        $facet['MinValue'] = $facet['RangeMin'];
                    }
                    if (isset($facet['RangeMax'])) {
                        $facet['MaxValue'] = $facet['RangeMax'];
                    }
                }

                // If the field is accessible via normal methods, including
                // a user-defined getter, prefer that
                $fieldValue = $rec->relObject($field);
                if (is_null($fieldValue) && $rec->hasMethod($meth = "get{$field}")) {
                    $fieldValue = $rec->$meth();
                }

                // If not, look for a VFI field
                if (!$fieldValue && $rec->hasExtension('VirtualFieldIndex')) {
                    $fieldValue = $rec->getVFI($field);
                }

                // If we found something, process it
                if (!empty($fieldValue)) {
                    // normalize so that it's iterable
                    if (!is_array($fieldValue) && !$fieldValue instanceof SS_List) {
                        $fieldValue = array($fieldValue);
                    }

                    foreach ($fieldValue as $obj) {
                        if (empty($obj)) {
                            continue;
                        }

                        // figure out the right label
                        if (is_object($obj) && $obj->hasMethod('Nice')) {
                            $lbl = $obj->Nice();
                        } elseif (is_object($obj) && !empty($obj->Title)) {
                            $lbl = $obj->Title;
                        } elseif (
                            is_numeric($obj) &&
                            !empty($facet['LabelFormat']) &&
                            $facet['LabelFormat'] === 'Currency' &&
                            $facet['Type'] !== ShopSearch::FACET_TYPE_RANGE // this one handles it via javascript
                        ) {
                            $tmp = Currency::create($field);
                            $tmp->setValue($obj);
                            $lbl = $tmp->Nice();
                        } else {
                            $lbl = (string)$obj;
                        }

                        // figure out the value for sorting
                        if (is_object($obj) && $obj->hasMethod('getAmount')) {
                            $val = $obj->getAmount();
                        } elseif (is_object($obj) && !empty($obj->ID)) {
                            $val = $obj->ID;
                        } else {
                            $val = (string)$obj;
                        }

                        // if it's a range facet, calculate the min and max
                        if ($facet['Type'] == ShopSearch::FACET_TYPE_RANGE) {
                            if (!isset($facet['MinValue']) || $val < $facet['MinValue']) {
                                $facet['MinValue'] = $val;
                                $facet['MinLabel'] = $lbl;
                            }
                            if (!isset($facet['RangeMin']) || $val < $facet['RangeMin']) {
                                $facet['RangeMin'] = $val;
                            }
                            if (!isset($facet['MaxValue']) || $val > $facet['MaxValue']) {
                                $facet['MaxValue'] = $val;
                                $facet['MaxLabel'] = $lbl;
                            }
                            if (!isset($facet['RangeMax']) || $val > $facet['RangeMax']) {
                                $facet['RangeMax'] = $val;
                            }
                        }

                        // Tally the value in the facets
                        if (!isset($facet['Values'][$val])) {
                            $facet['Values'][$val] = new ArrayData(array(
                                'Label'     => $lbl,
                                'Value'     => $val,
                                'Count'     => 1,
                            ));
                        } elseif ($facet['Values'][$val]) {
                            $facet['Values'][$val]->Count++;
                        }
                    }
                }
            }
        }

        // if we're auto-building the facets based on attributes,
        if ($autoFacetAttributes) {
            $facets = array_merge($this->buildAllAttributeFacets($matches), $facets);
        }

        // convert values to arraylist
        $out = new ArrayList();
        $sortValues = self::config()->sort_facet_values;
        foreach ($facets as $f) {
            if ($sortValues) {
                ksort($f['Values']);
            }
            $f['Values'] = new ArrayList($f['Values']);
            $out->push(new ArrayData($f));
        }

        return $out;
    }

    /**
     * NOTE: this will break if applied to something that's not a SiteTree subclass.
     * @param DataList|PaginatedList $matches
     * @param array $facet
     * @param int $typeID
     */
    protected function buildAttributeFacet($matches, array &$facet, $typeID)
    {
        $q = $matches instanceof PaginatedList ? $matches->getList()->dataQuery()->query() : $matches->dataQuery()->query();

        if (empty($facet['Label'])) {
            $type = ProductAttributeType::get()->byID($typeID);
            $facet['Label'] = $type->Label;
        }

        $baseTable = $q->getFrom();
        if (is_array($baseTable)) {
            $baseTable = reset($baseTable);
        }

        $q = $q->setSelect(array())
            ->selectField('"ProductAttributeValue"."ID"', 'Value')
            ->selectField('"ProductAttributeValue"."Value"', 'Label')
            ->selectField('count(distinct '.$baseTable.'."ID")', 'Count')
            ->selectField('"ProductAttributeValue"."Sort"')
            ->addInnerJoin('Product_StaticAttributeValues', $baseTable.'."ID" = "Product_StaticAttributeValues"."ProductID"')
            ->addInnerJoin('ProductAttributeValue', '"Product_StaticAttributeValues"."ProductAttributeValueID" = "ProductAttributeValue"."ID"')
            ->addWhere(sprintf("\"ProductAttributeValue\".\"TypeID\" = '%d'", $typeID))
            ->setOrderBy('"ProductAttributeValue"."Sort"', 'ASC')
            ->setGroupBy('"ProductAttributeValue"."ID"')
            ->execute()
        ;

        $facet['Values'] = array();
        foreach ($q as $row) {
            $facet['Values'][ $row['Value'] ] = new ArrayData($row);
        }
    }

    /**
     * Builds facets from all attributes present in the data set.
     * @param DataList|PaginatedList $matches
     * @return array
     */
    protected function buildAllAttributeFacets($matches)
    {
        $q = $matches instanceof PaginatedList ? $matches->getList()->dataQuery()->query() : $matches->dataQuery()->query();

        // this is the easiest way to get SiteTree vs SiteTree_Live
        $baseTable = $q->getFrom();
        if (is_array($baseTable)) {
            $baseTable = reset($baseTable);
        }

        $q = $q->setSelect(array())
            ->selectField('"ProductAttributeType"."ID"', 'TypeID')
            ->selectField('"ProductAttributeType"."Label"', 'TypeLabel')
            ->selectField('"ProductAttributeValue"."ID"', 'Value')
            ->selectField('"ProductAttributeValue"."Value"', 'Label')
            ->selectField('count(distinct '.$baseTable.'."ID")', 'Count')
            ->selectField('"ProductAttributeValue"."Sort"')
            ->addInnerJoin('Product_StaticAttributeTypes', $baseTable.'."ID" = "Product_StaticAttributeTypes"."ProductID"')
            ->addInnerJoin('ProductAttributeType', '"Product_StaticAttributeTypes"."ProductAttributeTypeID" = "ProductAttributeType"."ID"')
            ->addInnerJoin('Product_StaticAttributeValues', $baseTable.'."ID" = "Product_StaticAttributeValues"."ProductID"')
            ->addInnerJoin('ProductAttributeValue', '"Product_StaticAttributeValues"."ProductAttributeValueID" = "ProductAttributeValue"."ID"'
                . ' AND "ProductAttributeValue"."TypeID" = "ProductAttributeType"."ID"')
            ->setOrderBy(array(
                '"ProductAttributeType"."Label"' => 'ASC',
                '"ProductAttributeValue"."Sort"' => 'ASC',
            ))
            ->setGroupBy(array('"ProductAttributeValue"."ID"', '"ProductAttributeType"."ID"'))
            ->execute()
        ;

        $curType  = 0;
        $facets   = array();
        $curFacet = null;
        foreach ($q as $row) {
            if ($curType != $row['TypeID']) {
                if ($curType > 0) {
                    $facets['ATT'.$curType] = $curFacet;
                }
                $curType = $row['TypeID'];
                $curFacet = array(
                    'Label'  => $row['TypeLabel'],
                    'Source' => 'ATT'.$curType,
                    'Type'   => ShopSearch::FACET_TYPE_LINK,
                    'Values' => array(),
                );
            }

            unset($row['TypeID']);
            unset($row['TypeLabel']);
            $curFacet['Values'][ $row['Value'] ] = new ArrayData($row);
        }

        if ($curType > 0) {
            $facets['ATT'.$curType] = $curFacet;
        }
        return $facets;
    }

    /**
     * Inserts a "Link" field into the values for each facet which can be
     * used to get a filtered search based on that facets
     *
     * @param ArrayList $facets
     * @param array     $baseParams
     * @param string    $baseLink
     * @return ArrayList
     */
    public function insertFacetLinks(ArrayList $facets, array $baseParams, $baseLink)
    {
        $qs_f   = Config::inst()->get('ShopSearch', 'qs_filters');
        $qs_t   = Config::inst()->get('ShopSearch', 'qs_title');

        foreach ($facets as $facet) {
            switch ($facet->Type) {
                case ShopSearch::FACET_TYPE_RANGE:
                    $params = array_merge($baseParams, array());
                    if (!isset($params[$qs_f])) {
                        $params[$qs_f] = array();
                    }
                    $params[$qs_f][$facet->Source] = 'RANGEFACETVALUE';
                    $params[$qs_t] = $facet->Label . ': RANGEFACETLABEL';
                    $facet->Link = $baseLink . '?' . http_build_query($params);
                break;

                case ShopSearch::FACET_TYPE_CHECKBOX;
                    $facet->LinkDetails = json_encode(array(
                        'filter'    => $qs_f,
                        'source'    => $facet->Source,
                        'leaves'    => $facet->FilterOnlyLeaves,
                    ));

                    // fall through on purpose

                default:
                    foreach ($facet->Values as $value) {
                        // make a copy of the existing params
                        $params = array_merge($baseParams, array());

                        // add the filter for this value
                        if (!isset($params[$qs_f])) {
                            $params[$qs_f] = array();
                        }
                        if ($facet->Type == ShopSearch::FACET_TYPE_CHECKBOX) {
                            unset($params[$qs_f][$facet->Source]); // this will be figured out via javascript
                            $params[$qs_t] = ($value->Active ? 'Remove ' : '') . $facet->Label . ': ' . $value->Label;
                        } else {
                            $params[$qs_f][$facet->Source] = $value->Value;
                            $params[$qs_t] = $facet->Label . ': ' . $value->Label;
                        }

                        // build a new link
                        $value->Link = $baseLink . '?' . http_build_query($params);
                    }
            }
        }

        return $facets;
    }

    /**
     * @param ArrayList $children
     * @return array
     */
    protected function getRecursiveChildValues(ArrayList $children)
    {
        $out = array();

        foreach ($children as $child) {
            $out[$child->Value] = $child->Value;
            if (!empty($child->Children)) {
                $out += $this->getRecursiveChildValues($child->Children);
            }
        }

        return $out;
    }

    /**
     * For checkbox and range facets, this updates the state (checked and min/max)
     * based on current filter values.
     *
     * @param ArrayList $facets
     * @param array     $filters
     * @return ArrayList
     */
    public function updateFacetState(ArrayList $facets, array $filters)
    {
        foreach ($facets as $facet) {
            if ($facet->Type == ShopSearch::FACET_TYPE_CHECKBOX) {
                if (empty($filters[$facet->Source])) {
                    // If the filter is not being used at all, we count
                    // all values as active.
                    foreach ($facet->Values as $value) {
                        $value->Active = (bool)FacetHelper::config()->default_checkbox_state;
                    }
                } else {
                    $filterVals = $filters[$facet->Source];
                    if (!is_array($filterVals)) {
                        $filterVals = array($filterVals);
                    }
                    $this->updateCheckboxFacetState(
                        !empty($facet->NestedValues) ? $facet->NestedValues : $facet->Values,
                        $filterVals,
                        !empty($facet->FilterOnlyLeaves));
                }
            } elseif ($facet->Type == ShopSearch::FACET_TYPE_RANGE) {
                if (!empty($filters[$facet->Source]) && preg_match('/^RANGE\~(.+)\~(.+)$/', $filters[$facet->Source], $m)) {
                    $facet->MinValue = $m[1];
                    $facet->MaxValue = $m[2];
                }
            }
        }

        return $facets;
    }

    /**
     * For checkboxes, updates the state based on filters. Handles hierarchies and FilterOnlyLeaves
     * @param ArrayList $values
     * @param array     $filterVals
     * @param bool      $filterOnlyLeaves [optional]
     * @return bool - true if any of the children are true, false if all children are false
     */
    protected function updateCheckboxFacetState(ArrayList $values, array $filterVals, $filterOnlyLeaves=false)
    {
        $out = false;

        foreach ($values as $value) {
            if ($filterOnlyLeaves && !empty($value->Children)) {
                if (in_array($value->Value, $filterVals)) {
                    // This wouldn't be normal, but even if it's not a leaf, we want to handle
                    // the case where a filter might be set for this node. It should still show up correctly.
                    $value->Active = true;
                    foreach ($value->Children as $c) {
                        $c->Active = true;
                    }
                    // TODO: handle more than one level of recursion here
                } else {
                    $value->Active = $this->updateCheckboxFacetState($value->Children, $filterVals, $filterOnlyLeaves);
                }
            } else {
                $value->Active = in_array($value->Value, $filterVals);
            }

            if ($value->Active) {
                $out = true;
            }
        }

        return $out;
    }

    /**
     * If there are any facets (link or checkbox) that have a HierarchyDivider field
     * in the spec, transform them into a hierarchy so they can be displayed as such.
     *
     * @param ArrayList $facets
     * @return ArrayList
     */
    public function transformHierarchies(ArrayList $facets)
    {
        foreach ($facets as $facet) {
            if (!empty($facet->HierarchyDivider)) {
                $out = new ArrayList();
                $parentStack = array();

                foreach ($facet->Values as $value) {
                    if (empty($value->Label)) {
                        continue;
                    }
                    $value->FullLabel = $value->Label;

                    // Look for the most recent parent that matches the beginning of this one
                    while (count($parentStack) > 0) {
                        $curParent = $parentStack[ count($parentStack)-1 ];
                        if (strpos($value->Label, $curParent->FullLabel) === 0) {
                            if (!isset($curParent->Children)) {
                                $curParent->Children = new ArrayList();
                            }

                            // Modify the name so we only show the last component
                            $value->FullLabel = $value->Label;
                            $p = strrpos($value->Label, $facet->HierarchyDivider);
                            if ($p > -1) {
                                $value->Label = trim(substr($value->Label, $p + 1));
                            }

                            $curParent->Children->push($value);
                            break;
                        } else {
                            array_pop($parentStack);
                        }
                    }

                    // If we went all the way back to the root without a match, this is
                    // a new parent item
                    if (count($parentStack) == 0) {
                        $out->push($value);
                    }

                    // Each item could be a potential parent. If it's not it will get popped
                    // immediately on the next iteration
                    $parentStack[] = $value;
                }

                $facet->NestedValues = $out;
            }
        }

        return $facets;
    }
}


package org.jetbrains.plugins.hocon.misc

import com.intellij.psi.PsiElement
import com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider
import org.jetbrains.plugins.hocon.lang.HoconLanguage
import org.jetbrains.plugins.hocon.psi.HKeyedField

class HoconBreadcrumbsInfoProvider extends BreadcrumbsInfoProvider {
  def getElementTooltip(e: PsiElement) = null

  def getElementInfo(e: PsiElement): String = e match {
    case kf: HKeyedField => kf.key.map(_.stringValue).getOrElse("")
    case _ => ""
  }

  def acceptElement(e: PsiElement): Boolean = e match {
    case _: HKeyedField => true
    case _ => false
  }

  def getLanguages = Array(HoconLanguage)
}


export default connect()(App)


package com.google.cloud.resourcemanager.v3.samples;

// [START cloudresourcemanager_v3_generated_TagValuesSettings_GetTagValue_sync]
import com.google.cloud.resourcemanager.v3.TagValuesSettings;
import java.time.Duration;

public class SyncGetTagValue {

  public static void main(String[] args) throws Exception {
    syncGetTagValue();
  }

  public static void syncGetTagValue() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    TagValuesSettings.Builder tagValuesSettingsBuilder = TagValuesSettings.newBuilder();
    tagValuesSettingsBuilder
        .getTagValueSettings()
        .setRetrySettings(
            tagValuesSettingsBuilder.getTagValueSettings().getRetrySettings().toBuilder()
                .setTotalTimeout(Duration.ofSeconds(30))
                .build());
    TagValuesSettings tagValuesSettings = tagValuesSettingsBuilder.build();
  }
}
// [END cloudresourcemanager_v3_generated_TagValuesSettings_GetTagValue_sync]


{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block title %}Flasky{% endblock %}

{% block page_content %}

    {{ wtf.quick_form(form) }}

                #
                    {% for date_tmp in date_range_response %}
                        {{ date_tmp.strftime( '%m-%d' ) }}
{{ date_tmp.strftime( '%a' ) }}
                    {% endfor %}
                SUM

            {% for teacher in teacher_sum_response_data%}

                    {{ teacher}}

                    {% for date_tmp in date_range_response %}
                        {% if teacher_sum_response_data[teacher][date_tmp] %}
                            {{ teacher_sum_response_data[teacher][date_tmp].total_seconds()/3600 }}
                        {% else %}

                        {% endif %}
                    {% endfor %}

                    {{ teacher_sum_response_data[teacher]['total_classes_time'].total_seconds()/3600 }}

            {% endfor %}

{% endblock %}

{% block scripts %}
{{ super() }}
{{ pagedown.include_pagedown() }}
{% endblock %}