import Ember from 'ember';
import InputComponent from '../../mixins/component-input';
import InputMomentFormat from '../../mixins/component-input-moment-format';

export default Ember.Component.extend(InputComponent, InputMomentFormat, {
  type: 'date-bootstrap',
  fieldSettings: Ember.inject.service(),
  isInputGroup: true,

  momentFormat: Ember.computed('format', 'fieldSettings.dateFormat', function(){
    let format = this.get('format');
    if(Ember.isBlank(format)){
      return this.get('fieldSettings.dateFormat');
    } else {
      return format;
    }
  }),



  didInsertElement: function() {
    var domElement = this.$('input');
    domElement.datetimepicker({
      format: this.get('momentFormat')
    });

    if(!Ember.isBlank(this.get('minDate'))){
      domElement.data('DateTimePicker').minDate(this.get('minDate'));
    } else {
      domElement.data('DateTimePicker').minDate(false);
    }

    if(!Ember.isBlank(this.get('maxDate'))){
      domElement.data('DateTimePicker').maxDate(this.get('maxDate'));
    } else {
      domElement.data('DateTimePicker').maxDate(false);
    }
  },

  minDateObserver: Ember.observer('minDate', function(){
    var domElement = this.$('input');

    if(!Ember.isBlank(this.get('minDate'))){
      domElement.data('DateTimePicker').minDate(this.get('minDate'));
    } else {
      domElement.data('DateTimePicker').minDate(false);
    }
  }),

  maxDateObserver: Ember.observer('maxDate', function(){
    var domElement = this.$('input');

    if(!Ember.isBlank(this.get('maxDate'))){
      domElement.data('DateTimePicker').maxDate(this.get('maxDate'));
    } else {
      domElement.data('DateTimePicker').maxDate(false);
    }
  }),

  actions: {
    toggleCalendar: function(){
      this.$('input').data("DateTimePicker").toggle();
    }
  }
});

@@ -603,27 +603,27 @@
 ion() %7B%0A    
-var
+let
  domElement 
@@ -1161,35 +1161,35 @@
 function()%7B%0A    
-var
+let
  domElement = th
@@ -1194,32 +1194,90 @@
 this.$('input');
+%0A    this.sendAction('valueChanged', this.get('minDate'));
 %0A%0A    if(!Ember.
@@ -1524,11 +1524,11 @@
     
-var
+let
  dom
@@ -1553,16 +1553,74 @@
 input');
+%0A    this.sendAction('valueChanged', this.get('maxDate'));
 %0A%0A    if

set minDate and maxDate