import Ember from 'ember';
import layout from '../templates/components/uni-input-range';

const { computed } = Ember;
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;

export default Ember.Component.extend({
  classNames: ['uni-input-range'],
  layout,

  value: 0,
  offset: 1,
  max: MAX_SAFE_INTEGER,
  min: 0,
  placeholder: "placeholder",

  isDecrementDisabled: computed('value', function() {
    return this.get('value') <= this.get('min');
  }),
  isIncrementDisabled: computed('value', function() {
    return this.get('value') >= this.get('max');
  }),

  actions: {
    decrement() {
      if (this.get('isDecrementDisabled')) {
        return;
      }

      this.decrementProperty('value', this.get('offset'));
    },

    increment() {
      if (this.get('isIncrementDisabled')) {
        return;
      }

      this.incrementProperty('value', this.get('offset'));
    }
  }
});

import Ember from 'ember';
import layout from '../templates/components/uni-input-range';

const { Component, computed, K } = Ember;

export default Component.extend({
  classNames: ['uni-input-range'],
  layout,

  value: 0,
  offset: 1,
  max: Number.MAX_SAFE_INTEGER,
  min: 0,
  placeholder: "placeholder",
  onChange: K,

  isDecrementDisabled: computed('value', function() {
    return this.get('value') <= this.get('min');
  }),
  isIncrementDisabled: computed('value', function() {
    return this.get('value') >= this.get('max');
  }),

  actions: {
    decrement() {
      this.get('onChange')(Math.max(this.get('value') - this.get('offset'), this.get('min')));
    },

    increment() {
      this.get('onChange')(Math.min(this.get('value') + this.get('offset'), this.get('max')));
    }
  }
});

Change uni-input-range bindings (#33)