import React, { Component, PropTypes } from 'react'; // eslint-disable-line
import { connect as reduxConnect } from 'react-redux'; // eslint-disable-line

import { requestLogin, checkUser, isSSOEnabled } from '../../loginServices';
import Login from './Login';

class LoginCtrl extends Component {
  static contextTypes = {
    store: PropTypes.object,
    router: PropTypes.object,
    authFail: PropTypes.bool,
  }

  static propTypes = {
    authFail: PropTypes.bool,
    ssoEnabled: PropTypes.bool,
    autoLogin: PropTypes.shape({
      username: PropTypes.string.isRequired,
      password: PropTypes.string.isRequired,
    }),
  }

  constructor(props, context) {
    super(props);
    this.store = context.store;
    this.router = context.router;
    this.handleSubmit = this.handleSubmit.bind(this);
    this.sys = require('stripes-loader'); // eslint-disable-line
    this.okapiUrl = this.sys.okapi.url;
    this.tenant = this.sys.okapi.tenant;
    this.initialValues = { username: '', password: '' };
    this.state = { ssoActive: false };
    this.handleSSOLogin = this.handleSSOLogin.bind(this);
    if (props.autoLogin && props.autoLogin.username) {
      this.handleSubmit(props.autoLogin);
    }
  }

  componentWillMount() {
    checkUser(this.okapiUrl, this.store, this.tenant);
    isSSOEnabled(this.okapiUrl, this.store, this.tenant);
  }

  handleSubmit(data) {
    requestLogin(this.okapiUrl, this.store, this.tenant, data).then((response) => {
      if (response.status >= 400) {
        // eslint-disable-next-line no-param-reassign
        this.initialValues.username = data.username;
      }
    });
  }

  handleSSOLogin() {
    window.open(`${this.okapiUrl}/_/invoke/tenant/${this.tenant}/saml/login`, '_self');
  }

  render() {
    const { authFail, ssoEnabled } = this.props;

    return (
      <Login
        onSubmit={this.handleSubmit}
        authFail={authFail}
        initialValues={this.initialValues}
        handleSSOLogin={this.handleSSOLogin}
        ssoActive={ssoEnabled}
      />
    );
  }
}

function mapStateToProps(state) {
  return {
    authFail: state.okapi.authFailure,
    ssoEnabled: state.okapi.ssoEnabled,
  };
}

export default reduxConnect(mapStateToProps)(LoginCtrl);

@@ -1009,47 +1009,8 @@
  %7D;%0A
-    this.state = %7B ssoActive: false %7D;%0A
     

Remove unused state