import Ember from 'ember';
import layout from '../templates/components/login-form';

const {
  get,
  set,
  computed: { alias, or, equal }
} = Ember;

export default Ember.Component.extend({
  layout: layout,
  classNames: ['login'],
  tagName: 'form',

  formGroupClass: 'form-group',
  inputLabelClass: "control-label",
  inputClass: 'form-control',
  inputHelperClass: 'help-block',
  submitButtonClass: "btn btn-primary btn-raised btn-block",

  btnLabel: "login",
  errors: [],

  model: {
    identification: "",
    password: ""
  },

  textState: 'default',
  pending: equal('textState', 'pending'),
  isntValid: alias('changeset.isInvalid'),
  disable: or('isntValid', 'pending'),

  actions: {
    submit: function() {
      const promise = this.attrs.onSubmit(get(this, 'changeset'));

      set(this, 'textState', 'pending');
      promise.then(() => {
        if (!this.isDestroyed) {
          set(this, 'textState', "fulfilled");
        }
      }, (reason) => {
        this.set('error_message', reason.message);
        if (!this.isDestroyed) {
          set(this, 'textState', 'rejected');
        }
      });
    }
  }
});

@@ -685,16 +685,155 @@
 ing'),%0A%0A
+  didReceiveAttrs() %7B%0A    this._super(...arguments);%0A    if(this.changeset) %7B%0A      this.changeset.validate(%22identification%22);%0A    %7D%0A  %7D,%0A%0A
   action

remove initial check