import Ember from "ember";
import Promise from "liquid-fire/promise";
var capitalize = Ember.String.capitalize;

export default Ember.Mixin.create({
  growDuration: 250,
  growPixelsPerSecond: 200,
  growEasing: 'slide',

  transitionMap: Ember.inject.service('liquid-fire-transitions'),

  animateGrowth: function(elt, have, want) {
    this.get('transitionMap').incrementRunningTransitions();
    return Promise.all([
      this._adaptDimension(elt, 'width', have, want),
      this._adaptDimension(elt, 'height', have, want)
    ]).then(()=>{
      this.get('transitionMap').decrementRunningTransitions();
    });
  },

  _adaptDimension: function(elt, dimension, have, want) {
    var target = {};
    target['outer'+capitalize(dimension)] = [
      want[dimension],
      have[dimension],
    ];
    return Ember.$.Velocity(elt[0], target, {
      duration: this._durationFor(have[dimension], want[dimension]),
      queue: false,
      easing: this.get('growEasing')
    });
  },

  _durationFor: function(before, after) {
    return Math.min(this.get('growDuration'), 1000*Math.abs(before - after)/this.get('growPixelsPerSecond'));
  }

});

@@ -965,17 +965,58 @@
 Easing')
+ %7C%7C this.constructor.prototype.growEasing
 %0A
-
     %7D);%0A
@@ -1107,16 +1107,59 @@
 ration')
+ %7C%7C this.constructor.prototype.growDuration
 , 1000*M
@@ -1182,16 +1182,17 @@
  after)/
+(
 this.get
@@ -1215,16 +1215,67 @@
 econd'))
+ %7C%7C this.constructor.prototype.growPixelsPerSecond)
 ;%0A  %7D%0A%0A%7D

use own defaults if we've been set to undef