import Ember from 'ember';

export default Ember.Component.extend({
  tagName: 'input',

  setupBootstrapDatepicker: function() {
    var self = this;

    this.$().
      datepicker({
        autoclose: this.get('autoclose') || true,
        format: this.get('format') || 'dd.mm.yyyy',
        weekStart: this.get('weekStart') || 1,
        todayHighlight: this.get('todayHighlight') || false,
        todayBtn: this.get('todayBtn') || false
      }).
      datepicker('setDate', new Date(this.get('value'))).
      on('changeDate', function(event) {
        Ember.run(function() {
          self.didSelectDate(event);
        });
      });
  }.on('didInsertElement'),

  teardownBootstrapDatepicker: function() {
    // no-op
  }.on('willDestroyElement'),

  didSelectDate: function(event) {
    var date = this.$().datepicker('getUTCDate');
    this.set('value', date.toISOString());
  }
});

@@ -146,23 +146,50 @@
 this
-;%0A%0A
+,%0A 
     
-this.$()
+   element = this.$();%0A%0A    element
 .%0A  
@@ -477,66 +477,8 @@
 %7D).%0A
-      datepicker('setDate', new Date(this.get('value'))).%0A
     
@@ -603,16 +603,107 @@
      %7D);
+%0A%0A    if (value) %7B%0A      element.datepicker('setDate', new Date(this.get('value')));%0A    %7D;
 %0A  %7D.on(

Set value when it exists, or just leave it blank